FileResponse always creates a file

I just want to provide the user the possibility to get a generated (by pypandoc) docx file.
I have:
response = FileResponse(open(file_temp.name, ‘rb’),as_attachment=True)
return response

This works perfectly well, bur what ever the user’s answer (open with libreoffice, or download), a docx file is created in ~/Download/
I would like to avoid this.
How to do ?

It is most likely caused by the as_attachment=True you are passing to the FileResponse.

Looking at the documentation of the FileResponse object, there is a specific paragarph on this:

If as_attachment=True , the Content-Disposition header is set to attachment , which asks the browser to offer the file to the user as a download. Otherwise, a Content-Disposition header with a value of inline (the browser default) will be set only if a filename is available.

The relevant docs: Request and response objects | Django documentation | Django.

[tumpa02] tumpa02 https://forum.djangoproject.com/u/tumpa02
April 27

It is most likely caused by the |as_attachment=True| you are passing to
the |FileResponse|.

Looking at the documentation of the |FileResponse| object, there is a
specific paragarph on this:

If |as_attachment=True| , the |Content-Disposition| header is set to
>attachment> , which asks the browser to offer the file to the user
as a download. Otherwise, a |Content-Disposition| header with a
value of |inline| (the browser default) will be set only if a
filename is available.

Yes ! perfect, it works. Thanks a lot!
t.d.

(Attachment tdumont50.vcf is missing)

1 Like

Awesome, glad it works. :slight_smile: