2

I'm using mean stack

and formidable to upload file

the form has a multipart/form-data attribute

exports.create = function(req, res) {
    console.log(req.body);
}

but the rq.body is empty. How can I get it ?

5
  • Did you include the bodyParser middleware
    – adeneo
    Commented Jan 20, 2014 at 15:52
  • No because of andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html therefore I do the upload with formidable
    – Whisher
    Commented Jan 20, 2014 at 16:10
  • Then you'd have to follow the documentation for the plugin, seems like there is a form.parse method etc. Without the middleware that creates the req.body, it won't be there. Personally I use the bodyParser in production and have never seen anyone try to exploit the "file spam" issue.
    – adeneo
    Commented Jan 20, 2014 at 16:48
  • the signature is form.parse(req, function(err, fields, files) so ... there is no handle :(
    – Whisher
    Commented Jan 20, 2014 at 16:56
  • 1
    I got it console.log(fields.title); thanks for the tip :)
    – Whisher
    Commented Jan 22, 2014 at 9:37

1 Answer 1

1

If you are using formidable for multipart upload, you can get req.body fields in

form.parse(req, function(err, fields, files) 

fields.item

Not the answer you're looking for? Browse other questions tagged or ask your own question.