Multer: I can't get req.body

Created on 1 Sep 2016  路  6Comments  路  Source: expressjs/multer

Hi, I use multer to upload file and I want to attach other parameter in request In postman like this

screen shot 2559-09-01 at 17 35 45

my code
screen shot 2559-09-01 at 17 34 39

So I can't get req.body.test_body , How do I fix this??

Most helpful comment

What solved it for me was making sure the "Content-Type" header information in postman was not set; it had been set to "application/x-www-form-urlencoded" and removing allowed me to receive the file on my backend server as well as the req.body values.

All 6 comments

I don't see req.body.test_body referred to anywhere in your code? How is it not working?

also, please post the code using fenced code blocks, that way others can copy and search the code. Like so:

``````

Write code here

``````

I just use

 console.log(req.body);

So I see is {}

Your code screenshot doesn't show how it's all called so this is impossible for me to debug. Could you provide a minimum erring test case?

if your file input element is in the top of form then every data below that gets assigned to req.body after your image is uploaded, in the result of which body remains empty while you upload photo.. So take file input element to very bottom of your form so that req.body will have data from other input elements

What solved it for me was making sure the "Content-Type" header information in postman was not set; it had been set to "application/x-www-form-urlencoded" and removing allowed me to receive the file on my backend server as well as the req.body values.

I have solved and I will close this issues. sorry for last reply

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BlueOctober picture BlueOctober  路  3Comments

karandutt01 picture karandutt01  路  3Comments

nickretallack picture nickretallack  路  4Comments

samipjain picture samipjain  路  4Comments

kiwenlau picture kiwenlau  路  4Comments