Sending request with form-data failed! it send an empty object!

Hello community,
I need help solving this problem .

in this image sending a request is totally normal and I have my data stored in req.body as usual.


but here when I try to do the same thing with a form-data type, there is no data in the req.body, it’s an empty object. I don’t know why.
thank you for helping me

Hey @mohamedanouarjabri, Welcome to the community! :partying_face:

Depending on your API, for form data you try to check for form object in the request.
Try something like this in your Pre-request Script tab:

var req=pm.request.body;
console.log(req.formdata)

Good luck!

Thank you friend!
but what is “pm”?

It’s Postman’s sandbox object.
Learn more about it here :https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/

where should I write this??

I hope you figured it out.
The reason why is this because your presumed express server doesn’t parse multipart/form-data.
For it to parse this data you need to use something like multer.

So install multer, then in your main server file simple add the following.

const multer = require("multer");
const upload = multer();
// Add multer middleware for parsing multipart/form-data
router.post('test',upload.none(),(req,res,next)=>{
console.log(req.body);
});

This will attach multer middleware which will then parse your text multipart/form-data and reattach it to req.body which should now hold you desired data.

2 Likes