0

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
  • router.post("/upload", { ... what is this {? a random floating block of code for no reason? ... the start of an object declaration? ... I don't understand (neither does the compiler) Commented Jun 1, 2019 at 20:43

1 Answer 1

0

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();
        }
    })
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.