将blob-data和一个字符串一起发送到后端
我有一个奇怪的问题。 使用节点,react,express,mongodb - > Mern Stack。
因此,我的页面生成了一个PDF文件,然后将其发送到后端(作为BLOB数据)并存储在那里。 我遇到的问题是,现在我需要发送付款ID以及BLOB数据,以将订单保存在数据库中。我在一个帖子请求中都需要两者,以使其尽可能流畅:
await axios
.post(process.env.REACT_APP_SERVER_API + '/payment/cash', {
blobData,
paymentId
})
.then(async (res) => ...
这样。
之前,当我刚刚发送BLOB数据时,我可以通过写作简单地访问后端中的数据:
exports.createCashOrder = async (req, res) => {
const { filename } = req.file; // THIS RIGHT HERE
const fileHash = await genFileHash(filename);
try {
await saveOrder(filename, fileHash, "cash", paymentId);
//await sendOrderCreatedEmail(req.body, fileHash);
//await sendOrderReceivedConfirmEmail(req.body, fileHash);
res.send({ filename: filename });
}
但这不再起作用。发送该请求对象时,我无法访问该文件对象。 除了提出两个分开的帖子请求之外,都不尝试
req.body.blobData
req.body.blobData.file
req.file
任何想法如何实现这一目标?
欢呼,很高兴为您提供帮助!
I´ve got a weird problem.
Using Node, React, Express, MongoDB -> MERN Stack.
So my page generates a PDF file which then gets send to the backend (as blob data) and is being stored on there.
The problem I have, now I need to send a payment ID along with that blob data to save the order in the data base. I need both in one post request, to make it as smooth as possible:
await axios
.post(process.env.REACT_APP_SERVER_API + '/payment/cash', {
blobData,
paymentId
})
.then(async (res) => ...
like so.
Before, when I just sent the blob data, I could simply access the data in the backend by writing:
exports.createCashOrder = async (req, res) => {
const { filename } = req.file; // THIS RIGHT HERE
const fileHash = await genFileHash(filename);
try {
await saveOrder(filename, fileHash, "cash", paymentId);
//await sendOrderCreatedEmail(req.body, fileHash);
//await sendOrderReceivedConfirmEmail(req.body, fileHash);
res.send({ filename: filename });
}
But that doesn't work anymore. I dont have access to that file object anymore when sending that request object.
Neither by trying
req.body.blobData
req.body.blobData.file
req.file
Any idea how to achieve that, except from making two seperate post requests?
Glad for any help, cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将数据作为表单发送
,然后使用 multer mifdertare 表达。
Send the data as a form
And then use multer middleware to handle the form in express.