POSTMAN for multipage / form data

How do I use POSTMAN for Multipart / form-data that set up a header to test my controller that 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

      

+6


source to share


2 answers


enter image description here

Steps for Using Multipage / Form-Data in Postman



  • Create a new tab
  • Paste controller address
  • Set method type to POST
  • In the Body section, select the shape data
  • For each key that is a file, set the Value as File
+13


source


This is a long known problem for Postman. This can be a little tricky if you have a setup that includes, say, text or JSON for one part, but say a picture for the other. The key is to set the header Content-Type

to multipart/mixed

and then convert everything to a file. You can ignore the "convert it to file" step if it's text :)

Left this comment on: https://github.com/postmanlabs/postman-app-support/issues/1104

Ninja Update : Not sure if this will help anyone else, but there is a workaround for a specific scenario where you have multiple file / content types uploading in one multipart POST request.



  1. Set the Content-Type

    header to multipart/mixed

    .
  2. Select an option form-data

    in Body

    .
  3. Convert all your elements to files. The string content should become a text file, etc.
  4. Add each file by selecting by file

    adding key name.

This approach does not require manually specifying each Content-Type

or Content-Disposition

. The trick was to serialize all relevant content to a persistent file type. Hope this helps someone!

0


source







All Articles