Syntax issue with using Multer in Node.js

巧了我就是萌 提交于 2019-12-11 21:22:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!