0

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));
  };
Joseph
  • 5,548
  • 14
  • 57
  • 125
  • Does this answer your question? [Get a file name before saving it](https://stackoverflow.com/questions/50642065/get-a-file-name-before-saving-it) –  Sep 05 '21 at 15:17

0 Answers0