Skip to content Skip to sidebar Skip to footer

Download Anchor Link With Authorization Header

I have a link that I would like to add to my javascript (Marionette/Backbone) single page application that will download an Excel file to the user's local drive via the browser's f

Solution 1:

This not possible, because the only way to add HTTP headers is using the XHR, but XHR cannot be used to download files.

You could however use cookies to do that.

  1. Just set the cookie, with a returned value from the server.
  2. Wait till the user clicks the link.
  3. Invalidate the cookie after the user clicked the link.

Solution 2:

instead of passing token in headers pass it as url parameter

<ahref="/api/download/answers/{{token}}/{{survey._id}}"download="answers.csv" ></a>

Post a Comment for "Download Anchor Link With Authorization Header"