I've previously asked a question regarding passing files to the browser so a user receives a download prompt. However these files were really just strings creatd at the end of a function and it was simple to pass them to an iframe's src attribute for the desired effect.
Now I have a more ambitious requirement, I need to pass pre existing files of any format to the browser. I have attempted this using the following code:
response["Content-Disposition"] = "attachment; filename=nothing.xls"
With my original setup the following jQuery was sufficient to give the desired download prompt:
However this won't work anymore as I need to pass POST values to the function. my attempt to rectify that is below, but instead of a download prompt I get the file displayed as text.
Any ideas as to where I'm going wrong?
I've now changed everything so that passing the filename using POST returns an id number retrieved from the database which when appended to the URL causes the file to be returned. Thus /return_file/1/ returns a file with id 1.
where "download" is the id of an iframe.
There must be a better way of dealing with file downloads. Does anyone have ideas for a better method?
Why not just use
bob.read() the same way you previously used a differently-constructed string? Seems simplest!