I'm having trouble downloading an Excel file using axios.
Below is the code I have tried:
axios.post(backendURL + 'api/client?file_name='+file_name,params, {
file_name: file_name
}, {
responseType: 'blob'
}).then((response) => {
const url = URL.createObjectURL(new Blob([response.data], {
type: 'application/vnd.ms-excel'
}))
const link = document.createElement('a')
link.href = url
link.setAttribute('download', file_name)
document.body.appendChild(link)
link.click()
});
However, when I try to open the downloaded file "filename.xlsx", I receive an error stating "Excel cannot open the file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file".
I have searched online for solutions but none of them seem to work. Can someone please help me with this issue?