如何解决再次下载时损坏的Word文档
我对一个正在进行的机密项目有疑问,所以我不能分享太多细节。希望下面的代码足以至少提供一些有关错误的建议。
每当我以编程方式从锚链接下载单词blob时,它在第二次尝试均失败时仅表示由于文件已损坏而无法打开文件。我还看到该文件大了约14KB。
// route file
var buffer = await Packer.toBuffer(doc); // create buffer using DOCX.js Packer
res.header(
"output_name",`${unique_output_str}.docx` // <--- this is a template string which changes each time the document is generated,based on unique attributes that the user selects
);
res.send(Buffer.from(buffer));
我如何下载:
var response = await axios.patch(
path,// <--- this is defined elsewhere (not relevant to question)
formData,// <--- this is defined elsewhere (not relevant to question)
{ responseType: "blob" }
);
const url = URL.createObjectURL(
new Blob([response.data],{
type:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",})
);
const link = document.createElement("a");
link.href = url;
link.download = response.headers["output_name"];
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
提交表单后,我的第一次下载为什么会生成一个好的docx文件,但是将其他数据重新提交表单(更改文本以输入文本)会导致文件损坏?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。