Postman Tutorial Part 49 – How to Upload an Image Using Postman

As a part of Postman Tutorial – End to End , in this post, we will learn how can we upload an image using Postman or Perform Upload API testing using Postman.

Sample API:-

We will use Upload Image API provided by Imgur API.

If you see Upload Image API documentation, you will need below details to use API:-

Generating Client ID:-

You can get client id by Registering at Imgur site. Once you register, you need to Add an App. After that you can see your Client id as below:-

Creating Request in Postman:-

We have below things ready:-

URI:- https://api.imgur.com/3/upload

HTTP Verb :- POST

Client ID :- You know how to get.

Fields in Body :- See above image.

Let’s launch Postman app now and add URI and select POST method. We are expert in that now. If not, refer this article.

There is a different style to pass body to upload API. In normal POST request, we generally pass a JSON body by selecting “row” radio button under “Body” tab. In Upload API, we need to pass body by selecting “form-data” radio button. You can also notice the word “BODY formdata” in API documentation above.

Now you need to pass field values as shown in API documentation:-

Let’s first pass “image” field. Type key as “image” and remove focus from key field to save. 

Now mouse hover on “image” field, You should see a dropdown as below:-

When you click on drop down, you will see two options. Select “File” from that.

Once you select “File“, you will see a button to select image as shown below:-

Now click on “Select Files” control and Select the file. You will see file name as value.

Other fields are optional but we will pass “title” and “description” as below:-

We need to pass Client ID as an Authorization header as per API documentation shown above.

We are all set to upload image now. Click on Send button. You should see the response as below:-

{
    "data": {
        "id": "ZRtByZ0",
        "title": "Make Selenium Easy Logo",
        "description": "It is MSE Logo",
        "datetime": 1574775284,
        "type": "image/png",
        "animated": false,
        "width": 237,
        "height": 144,
        "size": 15031,
        "views": 0,
        "bandwidth": 0,
        "vote": null,
        "favorite": false,
        "nsfw": null,
        "section": null,
        "account_url": null,
        "account_id": 0,
        "is_ad": false,
        "in_most_viral": false,
        "has_sound": false,
        "tags": [],
        "ad_type": 0,
        "ad_url": "",
        "edited": "0",
        "in_gallery": false,
        "deletehash": "yuZFjBukkJlXAPI",
        "name": "",
        "link": "https://i.imgur.com/ZRtByZ0.png"
    },
    "success": true,
    "status": 200
}

You will see a field named “link” in JSON response. WHen you hit the URL in browser, you will see same uploaded image.

You can import above example collection from here. Do not forget to generate your client id and pass in Header tab.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Leave a Reply

Your email address will not be published. Required fields are marked *