下载blob流文件

//调接口后端返回文件流
fetch(`downloadTemplate`, {
      method: 'POST',
      mode: 'cors',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(body),
      credentials: 'include'
    })
        .then(async (res: any) => {
          let filename = '模板.xlsx';
          const blob = await res.blob();
          const url = window.URL || window.webkitURL;
          const downloadHref = url.createObjectURL(blob);
          const downloadLink = document.createElement('a');
          downloadLink.href = downloadHref;
          downloadLink.download = decodeURIComponent(filename);
          downloadLink.click();
        })
        .catch((e) => {
          message.error('获取文件信息失败');
        });

 

posted @ 2023-08-08 11:14  你风致  阅读(55)  评论(0编辑  收藏  举报