在Node.js中使用Multer的语法问题 [英] Syntax issue with using Multer in Node.js
本文介绍了在Node.js中使用Multer的语法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用本教程:
要将文件从React客户端上传到Node.js服务器端. 我在本教程中给出的POST路由存在问题, VS Code粘贴时显示语法错误.有人可以重新安排吗? 这是路线:
To upload a file from React client side to Node.js server side. I'm havng an issue with the POST route given in the tutorial, VS Code shows a syntax error when pasting it. Can anyone re-arrange it? This is the route :
router.post("/upload", {
upload(req, res, (err) => {
console.log("Request ---", req.body);
console.log("Request file ---", req.file);//Here you get file.
/*Now do where ever you want to do*/
if(!err)
return res.send(200).end();
});
};);
推荐答案
应该是这样
router.post('/upload', function (req, res) {
upload(req, res, function (err) {
console.log("Request ---", req.body);
console.log("Request file ---", req.file);//Here you get file.
/*Now do where ever you want to do*/
if(!err) {
return res.send(200).end();
}
})
})
这篇关于在Node.js中使用Multer的语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文