Download a file in JavaScript via Ajax
In the past I've executed my file download requests with provided an a
element with the download
attribute, or opening the link to the file in a new browser tab. In those cases the Web Application was secured via a session cookie so I had no problems with this approach.
But in my current project it's a bit different, because the API is secured with a Json Web Token which is not stored as a Cookie or in the localStorage. Therefore I would need to call the download url via Ajax (we use Axios for this in our case) so I can provide the JWT. The Ajax call returns me the File as a Blob, but now I'm not sure how I can prompt the Browser to download the file onto the file system of the user.
1631 views