在chrome中下载的PDF大部分是空白的,但在postman中可以
我正在尝试在我的浏览器中下载一个PDF,我已经使用axios从我正在运行的flask服务器将文本插入其中(通过PDF表单字段) 服务器端代码:在chrome中下载的PDF大部分是空白的,但在postman中可以,pdf,flask,axios,postman,Pdf,Flask,Axios,Postman,我正在尝试在我的浏览器中下载一个PDF,我已经使用axios从我正在运行的flask服务器将文本插入其中(通过PDF表单字段) 服务器端代码: def create_form(): # pdf buffer is a BytesIO object that contains the pdf ... pdf_buffer.seek(0) return send_file(pdf_buffer, as_attachment=True, attachment_filen
def create_form():
# pdf buffer is a BytesIO object that contains the pdf
...
pdf_buffer.seek(0)
return send_file(pdf_buffer, as_attachment=True, attachment_filename='file.pdf', mimetype='application/pdf')
当我在postman中使用保存和下载
选项测试该端点时,它工作正常,并在提示我下载文件后将所有文本覆盖在原始pdf上保存了该文件
然而,当我在chrome中使用axios时,pdf会自动下载,但pdf是空白的,除了我在表单字段中覆盖的新文本。原来的pdf内容完全消失了。
以下是在chrome中使用axios保存PDF的代码。
firefox的问题也一样
apiRequest({
apiEndpoint,
data,
responseType: 'blob',
}).then((resp) => {
let blob = new Blob([resp.data], { type: 'application/pdf' })
const url = window.URL.createObjectURL(blob);
let a = document.createElement("a");
a.href = url;
a.download = 'file.pdf';
document.body.appendChild(a);
a.click();
})
为什么这在postman中有效,而在chrome或firefox中却不起作用?我能想到的唯一一件事是,postman的
保存和下载
功能对收到的PDF文件的处理方式与axios POST的响应方式不同。我面临着同样的问题,也许你找到了解决方案,如果是的话,你能分享一下吗?如果你正在使用axios,请检查这个