Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSTMAN for Multipart/form-data

Tags:

How to use POSTMAN for Multipart/form-data which has customize header for testing my controller which takes 2 files as parameter (public ... controller( MultipartFile[] files))?

POST .... HTTP/1.1 . . . ---boundary123 Content-type:application/octet-stream content-Disposition: form-data filenale="abc.txt" name="someuniquename" [paylaod content](this is in xml format) ---boundary123 content-type:application/json content-Disposition:form-data name="metadata" {ID:"999"} ---boundary123 
like image 535
phalco Avatar asked May 25 '17 14:05

phalco


People also ask

Can we send multipart form data in Postman?

UPDATE: I have created a video on sending multipart/form-data requests to explain this better. Actually, Postman can do this. You DON'T need to add any headers, Postman will do this for you automatically. Be careful with explicit Content-Type header.

How do I post form data in Postman?

To use it, we need to select the x-www-form-urlencoded tab in the body of their request. We need to enter the key-value pairs for sending the request body to the server, and Postman will encode the desired data before sending it. Postman encodes both the key and the value.


2 Answers

enter image description here

Steps to use 'Multipart/form-data ' in Postman

  1. Create a new tab
  2. Insert controller Url
  3. Set method type as POST
  4. Under Body tab, select form-data
  5. For each key that is a file, set Value type as File
like image 67
Afridi Avatar answered Sep 21 '22 01:09

Afridi


I hope this will help others avoid long debugging efforts. Bottom line is that for some multipart uploads, you're just flat out of luck. For instance, if you need to do multipart/related, and need to express that in the Headers with a Content-Type, Postman can't help you. Primarily that's because Postman ONLY generates a random boundary, even if you add your own. The difficult part is that Postman will claim to be using your boundary in the Postman Console, but will actually be using a different boundary in the call. Thus the header boundary declared and the boundary actually used won't match.

Here's an example of a request from Postman, viewed both in the Postman Console and also in Fiddler. As you can see, Fiddler shows Postman is actually sending a random boundary, where Postman is claiming to use the provided boundary.

Fiddler vs Postman rendering of raw request

I really hope they fix that in Postman. At least show it the Postman Console, even if they don't fix the underlying issue. It's a great tool for most APIs, but if you're trying to hit a DICOM server, and being compliant about it... you're out of luck.

like image 30
Steven Borg Avatar answered Sep 20 '22 01:09

Steven Borg