javascript - 无法在 Node.js 中使用 Axios 将 Blob 保存到网络目录
问题描述
我有一个想要保存到网络位置的 blob(pdf)。到目前为止,我已经能够保存一个 pdf,但是即使我已经验证 blob 的大小表明它是完整的 PDF,它也是空的。
以下是我所做的一些步骤:
将 blob 发布到后端路由的函数
const postPDF = async () => {
const doc = docViewer.getDocument();
const xfdfString = await annotManager.exportAnnotations();
const options = { xfdfString };
const data = await doc.getFileData(options);
const arr = new Uint8Array(data);
const blob = new Blob([arr], { type: 'application/pdf' });
const token = state.token
const headers = {
'x-auth-token': token,
"content-type": blob.type
}
console.log(blob)
try {
const response = await axios.post(
postW4,
blob,
{ headers: headers });
console.log(response.data.message)
} catch (e) {
console.log(e);
}
};
用于发布和保存 BLOB(PDF) 到网络位置的后端代码:
const handleUpload = (req, res, next) => {
console.log('got here')
console.log(__dirname)
const tmp = fs.writeFileSync(
path.join(__dirname, './test.pdf'),
req,
);
}
router.post('/w4', async(req, res) => {
// upload.any(req);
handleUpload(req)
// res.send({ sucess: true })
});
我尝试将其转换为 formData 并尝试实现 multer,但仍然无法保存 pdf。
解决方案
推荐阅读
- java - 如何获取视频文件夹?
- android - 在 Xamarin Android 中为一组按钮设置动画
- java - whereGreaterThanOrEqualTo 和 whereArrayContains firestore 中的读取次数
- java - 如何使用spring boot在jira任务上上传名称中带有utf-8符号的文件作为附件
- shell - 我可以知道expect shell脚本中“cat”的等效命令是什么
- vue.js - visual-studio-code 中的自动右括号不适用于 Vue 文件
- html - 尝试使用 Webkit Animation CSS 重新创建 Tom Riddle 的文本效果
- .net-core - .netcore我想一次拉500条kafka消息,怎么配置
- python - 如何在 python 中对用户输入的数字求和?(仅当它们是偶数时)
- elasticsearch - 为什么在分析 Elasticsearch 慢速请求时数字不匹配