When I trying download exel(.xlsx) file with axios have problem and when I open this file.
when open exel file show this and press 'Yes' after that open this error
I try everything and find one difference between those two file which I download axios and postman. Differences: axios file encoding is UTF-8, postman file encoding is ANSI.
It's my code:
export const DownloadMonthly = (from, to) => {
return (dispatch) => {
return getAxios()
.get("/monthly/download", { params: {from, to}},
{
responseType: 'arraybuffer',
headers: {
'Content-Type': 'application/vnd.ms-excel'
}})
.then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data], {type: 'application/vnd.ms-excel'}));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', "monthly.xlsx");
document.body.appendChild(link);
link.click();
})
.catch((err) => {
console.error(err);
})
};
};