Syntax issue with using Multer in Node.js

2019-08-26 07:48发布

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条回答
做自己的国王
2楼-- · 2019-08-26 08:10

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();
        }
    })
})
查看更多
登录 后发表回答