[Fixed]-Django serves file.tar.gz not compressed

0👍

As Klaus D. said in comment this was a problem with encoding.

When I changed

if encoding is not None:
    response['Content-Encoding'] = encoding

to

response['Content-Encoding'] = 'tar'

Everything stated to working properly.

1👍

If you need to serve a tar.gz file do this,

    tar = tarfile.open("file_name.tar.gz", "r")    
    response = HttpResponse(tar, content_type='application/tar+gzip')
    response['Content-Disposition'] = 'attachment; filename="file_name.tar.gz"'
    return response

Leave a comment