python - Django/jQuery - read file and pass to browser as file download prompt -


I have asked the question about passing files from the browser so that the user got a download prompt though these files are actually functions At the end only the string was made and it was easy to pass them to the source attribute of the IFrame for the desired effect.

Now I have another ambitious requirement, I have to pass the previous files of any format in the browser I have tried to use the following code:

  Def return_file (request): try: bob = open (urllib.unquote (request.POST ["file"]), "RB" response = HttpResponse (content = bob, mimetype = "application / x-unknown") response ["Content-dispute"] = "attachment; filename = nothing.exles" returns http response (counter Except): Return HTTPPRPS (sys.exc_info ())  

With its original setup, the following was enough to give the desired download prompt to jQuery:

 < Code> jQuery ('# download'). Attr ("src" "/ return_file /");  

However this will not work anymore because I have to pass the post values ​​in the function. My try is that it is down but instead of a download signal I get the file displayed as text.

any Thinking where am I going wrong?

Thanks!

EDIT:

I have changed everything now so that by going through the file name using POST An ID number from the database can be returned, which is due to returning the file associated with the URL, thus returns a file with / return_file / 1 / ID1.

JQuery ('# download'). Attr ("src", "");

Yes "Download" is an IFrame ID.

There should be a better way to handle file downloads. Can anyone be considered better?

< P>

Why not only bob.read () In the same way did you previously used a different string? Looks simple!


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -