Downloading excel(.xlsx) with blob and FileSaver.js in vue project getting coruppted
10,330
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
Author by
Jitu
Updated on June 23, 2022Comments
-
Jitu almost 2 years
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.
-
Jitu over 6 yearsThank you Mazino, Actully I was missing the responseType, your solution working. and also I have soloved it by sending the responseType = 'arraybuffer' and blob the response and then saved it.
-
Ajithkumar S almost 5 yearsThank you @MazinoSUkah.. It worked like a charm.. :)