【问题标题】:Syntax issue with using Multer in Node.js在 Node.js 中使用 Multer 的语法问题
【发布时间】:2019-06-01 20:35:01
【问题描述】:

我一直在使用这个教程:

https://medium.com/@mahesh_joshi/reactjs-nodejs-upload-image-how-to-upload-image-using-reactjs-and-nodejs-multer-918dc66d304c

将文件从 React 客户端上传到 Node.js 服务器端。 我对教程中给出的 POST 路线有疑问, VS Code 在粘贴时显示语法错误。谁能重新安排一下? 这是路线:

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", { ...这是什么{?无缘无故的随机浮动代码块? ...对象声明的开始? ...我不明白(编译器也不明白)

标签: javascript node.js reactjs file-upload multer


【解决方案1】:

应该是这样的

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();
        }
    })
})

【讨论】:

    猜你喜欢
    • 2017-05-22
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2021-01-24
    • 2022-11-24
    • 2017-12-03
    相关资源
    最近更新 更多