【发布时间】:2020-03-04 09:16:49
【问题描述】:
以下是 pdf 缓冲区。我想将缓冲区转换为 pdf 文件。
data = {
"file": {
"type": "Buffer",
"data": [
102,
24,
62
]
},
}
res.send( data );
【问题讨论】:
-
缓冲区从何而来?如果您正在创建它,那么您应该将其write 放入一个文件并将其发回。
-
缓冲区是pdf文件
-
那为什么不直接把文件发回去呢?您可以创建一个 readstream 并将其传递给响应
-
我试图发送 pdf 文件以及相关的 json 数据 {status:200, fileBuffer: fileBuffer, "otherJsonData": {"a": 1, "b":2} } 但它是无法同时使用 res.download 和 res.send,所以我将 pdf 文件转换为缓冲区然后发送它
标签: node.js express httpresponse pdfkit