Download file using ajax call - boring
Asked
I have a Struts2 action in the server side for file downloading.
2019 modern browsers updateThis is the approach I'd now recommend with a few caveats:
- A relatively modern browser is required
- If the file is expected to be very large you should likely do something similar to the original approach (iframe and cookie) because some of the below operations could likely consume system memory at least as large as the file being downloaded and/or other interesting CPU side effects.
You can with HTML5NB: The file data returned MUST be base64 encoded because you cannot JSON encode binary dataIn my response I have a data structure that looks like this:
The simple way to make the browser downloads a file is to make the request like that:
-
-