I want to save my excel file coming from the API. I've done successfully but I wanted to get its the excel file filename in the API. Is it possible?
export const exportPersonsService = (data) => {
return getAxiosService()
.post(`persons/excel/export`, data, {
headers: {
'Content-Disposition': 'attachment; filename=template.xlsx',
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
responseType: 'arraybuffer',
})
.then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'persons.xlsx');
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(url);
})
.catch((error) => console.log(error));
};