Reputation: 377
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
Upvotes: 32
Views: 118994
Reputation: 7341
for what it's worth, because I wasted a couple of hours on this :
I have an endpoint that will accept multipart, with one part being either image/* or audio/*.
The openApi I imported in Postman was like this :
encoding:
asset_file:
contentType: image/*, audio/*
The problem is that I was trying to upload an audio and the server checks the value of the contentType
received, depending on what it starts with.
The problem in Postman is that the Content-Type
column is hidden by default
It took me a while to realize it and then display it so that I could modify it myself
Upvotes: 1
Reputation: 801
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.
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.
Upvotes: 11
Reputation: 1513
This video describes how to post multipart/form-data using postman. I uploaded a text file with Content-Type of multipart/form-data.
Upvotes: -5
Reputation: 746
This is a long-known issue for Postman. It can be a bit tricky if you have a set up that involves using say text or JSON for one part but say a picture for another. The key is to set the Content-Type
Header to multipart/mixed
and then to convert everything into a file. You can ignore the "convert it into a 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 types / content types being uploaded in a single multipart POST request.
Content-Type
to multipart/mixed
.form-data
option in Body
.file
, adding a key name.This approach doesn't require actually manually specifying each Content-Type
or Content-Disposition
. The trick here was to serialize all relevant content into a persistent file type. Hope that helps someone!
Upvotes: 3
Reputation: 6922
Steps to use 'Multipart/form-data ' in Postman
Upvotes: 68