首页 > 解决方案 > 使用axios下载pdf失败(空白页)

问题描述

 ...
 PdfWriter.getInstance(document, outputStream); // outputstream from java 

我通过 fetch api 和 postman 成功下载了这个 pdf 文件,但通过 axios 失败,即使大小正常。

// I successfully downloaded this pdf file by fetch api and postman, but failed by axios, even though the size was normal(blank content).
axios({
 url: `xxx`,
 method: 'get',
 responseType: 'arraybuffer'
}).then(resp => {
  const url = window.URL.createObjectURL(new Blob([resp.data], {type:"application/pdf"}));
  const link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', 'test.pdf');
  document.body.appendChild(link);
  link.click();
})

有人能帮我吗?

标签: axios

解决方案


删除或卸载 MockJS,然后再试一次!


推荐阅读