How to upload image file using POST request in Robot Framework

923 views
Skip to first unread message

Sheetal Shahare

unread,
Feb 8, 2021, 9:24:30 PM2/8/21
to robotframework-users
How to upload image file using POST request in Robot Framework?

Dave Amies

unread,
Feb 10, 2021, 5:01:28 AM2/10/21
to robotframework-users
Hi Sheetal,

Are you trying to upload an image using the post method of the Requests Library?

How you go about this vary's depending on the application, best bet is to do the upload in a browser with dev tools open and then look at the request body and replicate that.

The most common methods i've seen are:
1) read the image file, then base64 encode the image data, this base64 encoded string then becomes the post body, and the content type header is image/jpg, image/png, etc depending on the image type
2) read the image file, then base64 encode the image data, this base64 encoded string is then embedded inside an XML or JSON element, other elements often included the filename and content type

These are the most common and simply ways an application could want an image uploaded, I have seen more complex processes as well.

I hope I understood your question and this helps,

Dave.

Irkham Agung Karunia

unread,
Mar 23, 2021, 8:35:09 PM3/23/21
to robotframework-users
Hi Dave, 

can you give some example for this option?
i try some combination but still not working

Dave Amies

unread,
Mar 24, 2021, 1:05:27 AM3/24/21
to robotframework-users
Hi Irkham,

Unfortunately not, when I dealt with these upload forms I was using loadrunner, and that was a previous customer's site so I don;t have access to those scripts now anyway. 

I just gave the concepts here, the concept with robot framework requests library and loadrunner web protocol are similar, but robot framework you have access to all the python libraries so that makes things a lot easier.

If you google "robotframework base64 encode" you can find this example https://groups.google.com/g/robotframework-users/c/OM-EQirmMq0

Dave.

Reply all
Reply to author
Forward
0 new messages