axios - 使用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();
})
有人能帮我吗?
解决方案
删除或卸载 MockJS,然后再试一次!
推荐阅读
- python - 如何让 Sympy(在 python 中)插入函数的给定值?
- c++ - 如何使用范围枚举模板参数设置数组别名的长度而不进行强制转换
- c - 为什么我的“c”变量在 for 循环中到达第三个循环时呈指数增长?
- javascript - 使用不和谐 js 删除用户消息中的特定嵌入(或显示正确存储的嵌入)
- c++ - 不知道如何解决:“。”之前的预期主表达式 令牌
- react-native - 以高性能的方式渲染 FlatList 的视频
- python - TF Keras 模型输入上的低通滤波器
- python - 如何使用 for 循环和方法查询创建新的数据框来过滤我已经存在的数据框?
- function - 使用 dat.gui 修改函数的参数并修改其图形
- pine-script - 如何获得pinescript中所有蜡烛的较高高和较低低值?