Returning a FileResponse from a POST request

I’m creating a pdf report view that shows a progress bar while the pdf is being generated using Celery. I have the page showing the progress bar working well and on completion of the pdf task have some javascript code that performs a POST to the same URL with a few JSON parameters. In the view I check to see if the request is a POST then use FileResponse to return the pdf file generated by the task. Everything seems to be good but no pdf is displayed on the browser, looking at chrome network tool it shows the POST request with response header that looks good with Content-Length set the correct size of the pdf and type of application/pdf.

Here’s my POST section of my view:

if request.method == ‘POST’:
post_data = json.loads(request.body.decode(“utf-8”))
id = post_data[‘search_id’]
file_name = post_data[‘file_name’]
return FileResponse(open(file_name, “rb”), as_attachment=False, filename= id + “.pdf” )

I have verified the json parameters get passed up from the browser correctly. I assume that downloading a file from a POST request is allowed but I can’t find anything to says it is or not. Any help will be appreciated. Doug

Welcome @dougm !
Whenever you issue a request from Javascript, it’s up to the Javascript to handle the response. This means you need to write something to cause that file to be rendered. (It’s the Javascript that gets the response, not the browser.)

Thanks, that makes sense, I’ll go down that route to see what trouble I can get in to :slight_smile: