js-file-download does not downloads png/jpg files.
afrazahmad21 opened this issue · comments
Afraz Ahmad commented
Hi,
I am currently working in a react project. I want to download file via url (http://developers.iqvis.com:8082/5b339dae14dd2757b711e56f/1530185975056-iqvis.png) but downloading png file and opening it gives error (Fatal error reading a png file: Not a png file)
here is sample code
axios.get(apiUrl)
.then((response) => {
fileDownlaod(response.data, fileName);
})
.catch((err) => {
console.log(err);
});
Jody Clements commented
Try adding the following option to your get request :
{ responseType: 'arraybuffer' }
eg:
axios.get(apiUrl, { responseType: 'arraybuffer' } )
.then((response) => {
fileDownload(response.data, fileName);
})
.catch((err) => {
console.log(err);
});
That worked for me.
Vilberg Eliasson commented
Should this issue be closed?
Kenneth Jiang commented
Thank you @neomorphic for offering the solution. Closing this issue now. @afrazahmad21 feel free to re-open it if the solution doesn't work for you!