H
H
Hukyl2021-03-18 19:01:21
Django
Hukyl, 2021-03-18 19:01:21

How can I send a file from Django to Mozilla Firefox for download?

There is a zip archive, I want to send it to HttpResponse or FileResponse, the archive is in bytes, I specified the content-type, content-encoding, content-disposition, and everything seems to be correct, in Google Chrome the download works, but in Mozilla it doesn’t, I don’t know, in what's the problem

# часть кода опущено
    creator = XmlCreator(tables_preset=tables_preset, data=data)
    try:
        xml_archive = creator.archive()
    except Exception:
        raise Http404("User data to create XML was not found")
    else:
        response = FileResponse(
            xml_archive, as_attachment=True,
            filename=f'{tables_preset["user"]}-{period_from.strftime("%Y-%m-%d")}.zip'
        )
        response.headers['Content-Encoding'] = None
        # response = HttpResponse(xml_archive, content_type='application/zip')
        # response['Content-Disposition'] = f'attachment; filename="{tables_preset["user"]}-{period_from.strftime("%Y-%m-%d")}.zip"'
        # response['Content-Encoding'] = 'gzip'
        return response

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question