Sending request with file and text

Describe the bug
I would like to send a request that contains both a file and some meta data about the file.

However, when I create the request, I can’t set the file in the x-www-form-urlencoded so when I send it, it does not have file information.

When I create the request using form-data, it contains the file information, but my server side API receives an empty body

To Reproduce
Steps to reproduce the behavior:

  1. create a new request
  2. set body to form-data
  3. type in ‘image’ for key and select a file for value
  4. type in ‘affiliation’ for key and type in affiliation value
  5. type in ‘name’ for key and type in ‘test’ for value
  6. select “Post”
  7. type in the URL
  8. click the send button

repeat steps, but select x-www-form-urlencoded

Expected behavior
I expect the image data and the other data to come through in my api, but it doesn’t

Screenshots
Here is the result using form-data. NOTE: my back end API has failed validation as it cannot find ‘affiliation’, ‘image’ or ‘name’ in the request (even though it’s present in the form-data)

Here is the result using www-form-urlencoded. NOTE: the back end has created the entry in the DB, but it is missing the ‘image’ portion of the request (it’s not present in the request)

App information (please complete the following information):

  • App Type : REST API
  • Postman Version - latest version
  • OS: windows 7

Additional context
I have searched the web for a way to do this and it seem like there isn’t a good answer

Can you double check by opening the Postman Console that Postman is indeed not sending the other form-data fields as your API complains?

IF it were sending the other form-data fields… then the code would execute correctly… right?
as the only data that I am setting is the relevant data for the API being tested.

@vdespa I met the same situation. I don’t know why postman sent a null object as the body in my case if I was using form-data mode trying to send text data and files data together. If i use the x-www-form-urlencoded to send the text data, it will be ok to send the key-value pairs with only problem is not able to send files together. What is the trick to actually to use form-data mode in current version? I remember few month ago when I used postman, I was able to send files with text together.

I also came across this requirement…i.e. to send file (image) along with some text parameters in x-www-form-urlencoded…
There is no option to select the type of parameter (file or text) as its available in form-data…
If I send this as form-data with a header as “Content-Type application/x-www-urlencoded”, then the image does not get sent successfully…
Any idea how can this be overcome? I am kind of blocked

Maybe I am wrong, but AFAIK x-www-form-urlencoded is not suitable for data (as the information will be URL encoded).

You should use multipart/form-data instead. Have you tried that?

Thanks @vdespa
The multipart/form-data does work

So I am pretty sure you are “kind of out of luck” on this. Here is the “issue” for this going back more than 5 years … up shot, there is a work around if you turn your content into files. Otherwise, you will have to wait for Postman to catchup to curl :stuck_out_tongue:

https://github.com/postmanlabs/postman-app-support/issues/1104