问题
i've been using this tutorial :
https://medium.com/@mahesh_joshi/reactjs-nodejs-upload-image-how-to-upload-image-using-reactjs-and-nodejs-multer-918dc66d304c
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();
});
};);
回答1:
It should be like this
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();
}
})
})
来源:https://stackoverflow.com/questions/56410236/syntax-issue-with-using-multer-in-node-js