Nathiel Barros
Nathiel Barros

Reputation: 715

How to make a Request with a Image using postman

In my WebApi project, this is my Current

http://localhost:52494/api/v1/Register/RegisterUser

And the parameter is a model :

public class DataUserModel
{
    public string Gender { get; set; }
    public int PhoneNumber { get; set; }
    public byte[] ProfileImage { get; set; }
}

How to set up the Postman to send this request with a binary image and the others properties as JSON! I usually do :

Content-Type:application/json
{
   "Gender":'F',
   "PhoneNumber":99999999,
}

Upvotes: 1

Views: 2392

Answers (1)

Janus Pienaar
Janus Pienaar

Reputation: 1103

You basically have two options here:

  • Send JSON and Binary data in 2 separate requests. I prefer this method, keeps it clean and more readable.
  • Combine both JSON and Binary into one request. This is a bit more complex and you would need to use Content-Type: multipart/form-data; to achieve this result.

Have a look at http://blog.marcinbudny.com/2014/02/sending-binary-data-along-with-rest-api.html it describes both scenarios in detail.

In Postman (Pseudo Code) you would have something like the following:

POST http://localhost:52494/api/v1/Register/RegisterUser HTTP/1.1

Content-Type: multipart/form-data; boundary="01ead4a5-7a67-4703-ad02-589886e00923"
Host: 127.0.0.1:53908
Content-Length: 707419


--01ead4a5-7a67-4703-ad02-589886e00923
Content-Type: application/json; charset=utf-8
Content-Disposition: form-data; name=imageset


{"Gender":"F", "PhoneNumber" : 99999999}
--01ead4a5-7a67-4703-ad02-589886e00923
Content-Type: image/jpeg
Content-Disposition: form-data; name=image0; filename=Small-Talk-image.jpg



{YOUR IMAGE CONTENT HERE}
--01ead4a5-7a67-4703-ad02-589886e00923
Content-Type: image/jpeg
Content-Disposition: form-data; name=image2; filename=url.jpg

Upvotes: 3

Related Questions