I am trying to download file by sending an Api request in my Vue project, and with response data I am trying to save the file using blob and FileSaver.js
sendAjaxCall.then(response => {
let file = new Blob([response.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
FileSaver.saveAs(file, 'Export2.xlsx')
}
But I can not open the file, it is getting corrupted.
try this
return Vue.axios.get(`api/excel_sheet`, {
responseType: 'blob',
}).then(response => {
FileSaver.saveAs(response.data, 'Export2.xlsx')
};
u need to specify the response type as blob