How to handle FormData from express 4

后端 未结 1 1391
迷失自我
迷失自我 2020-11-27 04:59

I tried sending some form data to my node server but req.body has none of my form fields the node side

 var express = require(\'express\')
var a         


        
相关标签:
1条回答
  • 2020-11-27 05:45

    body-parser doesn't handle multipart bodies, which is what FormData is submitted as.

    Instead, use a module like multer.

    For example, to retrieve the (regular) fields of a request:

    const multer = require('multer');
    const upload = multer();
    
    app.post('/send', upload.none(), (req, res) => {
      const formData = req.body;
      console.log('form data', formData);
      res.sendStatus(200);
    });
    
    0 讨论(0)
提交回复
热议问题