Reputation: 5960
I have an API which when called through browser's URL downloads a .csv file. However, I cannot get the same behaviour when trying to call the above endpoint programmatically (e.g. by using axios
library). Instead, I have used js-file-download
as to make it work:
let res = await axios.get(testUrl);
FileDownload(res.data, `report ${moment().format()}.csv`);
So, my question is why the latter works differently than the former?
Upvotes: 0
Views: 35
Reputation: 944205
The entire point of Ajax is that the response to the HTTP request is processed by your JavaScript instead of the browser's default handling.
So instead of being saved to the Downloads folder, the response is given to your JavaScript.
Upvotes: 1