Sarah
Sarah

Reputation: 81

simply way to handle post data/image in node js through Postman Form-Data

Is there a way to post form-data through postman using Nodejs. I have seen many platforms but the author is using the front-end to post data which manipulates the back-end code. I want to understand the code

Upvotes: 1

Views: 1553

Answers (2)

Aravind
Aravind

Reputation: 680

Yes you can send the data using form-data in post man.
You can see the formdata under the body section in this form data you have to change the type from text to file post man form-data


after changing to file type you can browse your local machine. to choose the image



You can further parse the files in node js using formidable. You can install this package and you can configure to your needs. It can handle upto 1000 files



Coming to code part in node js. First configure the formidable

const form = new formidable.IncomingForm({
      multiples: true,
      keepExtensions: true,
    });

After that you have to parse the fieldvalue and file

form.parse(req);

Then you can seperate the value and files uisng

form.on("file", (field, file) => {}) //For file
form.on("field", (fieldName, fieldValue) => {}) //for fieldvalue

Hope this one helps for you!!

Upvotes: 2

Lampros Tampourlos
Lampros Tampourlos

Reputation: 126

Sure thing. Set request type to POST and then define your data in the request body

check this out

https://learning.postman.com/docs/sending-requests/requests/#sending-body-data

Upvotes: 1

Related Questions