862

I am currently using the Chrome Addon Postman - REST Client to easily create POST / GET request.

Now I want to debug an upload script and I am looking for a way to make requests encoded as "multipart/form-data" so that I can send also a file.

Vamsi Jayavarapu
  • 105
  • 2
  • 11
Valentin Despa
  • 40,712
  • 18
  • 80
  • 106

2 Answers2

1838

UPDATE: I have created a video on sending multipart/form-data requests to explain this better.


Actually, Postman can do this.

enter image description here

Full example:

enter image description here

You DON'T need to add any headers, Postman will do this for you automatically.

enter image description here

Make sure you check the comment from @maxkoryukov

Be careful with explicit Content-Type header. Better - do not set it's value, the Postman is smart enough to fill this header for you. BUT, if you want to set the Content-Type: multipart/form-data - do not forget about boundary field.

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
  • 13
    postman's form-data params sometimes doesn't get into my Laravel API's REST methods. Not sure why. – Lotus Dec 08 '13 at 17:17
  • @Valentin, I tried this with the localhost on Google App Engine (Python 2.7), but it threw a internal server error (500). Is there something else you had to do to get it to work? – Diode Dan Jan 24 '14 at 02:41
  • Google App Engine gave the internal server error? – Valentin Despa Jan 24 '14 at 10:56
  • @YonatanNir You must select POST, instead of the pre-selected GET method. – Valentin Despa Oct 07 '15 at 16:57
  • I did. When selecting POST it added an option to send a header and body. The body has 3 tabs: Raw, Form, Files. In the form tab you can add key-values for parameters but the files are in a separate tab and there is no option to allocate them to a parameter. – CodeMonkey Oct 07 '15 at 17:46
  • @YonatanNir I have added a newer screenshot with a recent Postman version. Hope this helps. – Valentin Despa Oct 07 '15 at 18:17
  • 7
    Error `"There is no multipart/form-data content in request"` – Jemshit Nov 23 '15 at 13:09
  • It isn't working with PUT request – mohit Mar 02 '16 at 10:44
  • 77
    Be careful with explicit **`Content-Type`** header. Better - do not set it's value, the Postman is smart enough to fill this header for you. **BUT**, if you want to set the `Content-Type: multipart/form-data` - do not forget about **boudary** field. – maxkoryukov Aug 21 '16 at 02:52
  • 2
    @maxkoryukov Thank your for your comments. My API was not working at all while I was trying multipart file upload using Postman client. Suddenly I came across your comments and this literally save my ass :). But, could you explain more on the `boundary` field. I know that postman adds boundary on its own. How do I do it manually? :) – Adithya Upadhya Jan 02 '17 at 11:19
  • 2
    @oathkeeper, here is a good enough explanation of **boundary**: http://stackoverflow.com/a/20321259/1115187 In two words: you could set *boundary* manually and there are couple of simple rules. – maxkoryukov Jan 02 '17 at 14:07
  • In my case, I have to change "fileName" to "file" for my Ruby on Rails server. – Michael Wang Jan 19 '17 at 04:37
  • Really Helpful. – Asim Khan Nov 08 '17 at 08:00
  • 2
    Remember that you have to explicitly type a key name. E.g. "file". Otherwise it doesn't work. – NickBeaugié Mar 19 '18 at 09:40
  • Yes, you are right. Perhaps you's remind user to remove "Content-Type" header explicitly. Otherwise I get this error: https://stackoverflow.com/questions/17415084/multipart-data-post-using-python-requests-no-multipart-boundary-was-found – Leon Apr 18 '18 at 07:49
  • heads up that in Postman 7.1.0, I had to manually enter text in the "Key" column, as leaving it blank kept giving me an error. – Ryan Lee Simms May 17 '19 at 20:46
  • 2
    Did you really upload a 28 min video for this? – Ozgur Akcali Jun 12 '19 at 15:46
  • Useful info, thanks... Sometimes we have to set it manually.. In my case I have to change from text to json – Lukman Sep 04 '21 at 16:27
  • @ValentinDespa, what if we want to send image and a text simultaneously? What do we do then. – Sunil Shah Jan 06 '22 at 13:27
  • @SunilShah add another key with the next and set the proper content type – Valentin Despa Jan 07 '22 at 05:50
250

The usual error is one tries to put Content-Type: {multipart/form-data} into the header of the post request. That will fail, it is best to let Postman do it for you. For example:

Suggestion To Load Via Postman Body Part

Fails If In Header Common Error

Works should remove content type from the Header

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
Hung Vu
  • 5,624
  • 2
  • 30
  • 27