React excel file download corrupt

后端 未结 1 1760
南笙
南笙 2021-01-05 06:54

Im trying to download an Excel file in Reactjs by calling a Spring REST endpoint but I\'m running into issues with a corrupt file.

React call...

getF         


        
相关标签:
1条回答
  • 2021-01-05 07:39

    You just have to add response type to the axios request:

    responseType: 'arraybuffer'
    

    In my application following function downloads excel file:

    function exportIssues() {
      axios.get('/issues/export', { responseType: 'arraybuffer' })
        .then((response) => {
          var blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
          fileSaver.saveAs(blob, 'fixi.xlsx');
        });
    }
    
    0 讨论(0)
提交回复
热议问题