I'm using a custom header token so downloading the report via a simple link is impossible; the request has to be made via XHR
. My two-part solution:
Returned the CSV data from the API directly as text, removing file
attachment
headers. This is the correct solution, anyway, because it keeps the REST JSON API unconcerned with file downloads, which are a browser concept.Wrapped the API response data in a
Blob
, and then used https://github.com/eligrey/FileSaver.js to initiate a file download.
A drawback is this requires IE10+, but that is okay in my case.