Saturday 2 September 2017

Upload a file via PUT request using Jmeter

If you are unable to upload a file via PUT request using Jmeter, then you are on the right Page.


For PUT request, the Jmeter does not provide option “Use multipart/form-data”. It is disabled. 



Solution:-
Launch wireshark
Execute the PUT request from the browser and capture it in wireshark.


Open Jmeter and add an HTTP sampler. Change the Method to PUT and add server Name, Protocol. See the highlighted items in the below screenshot.


Now, you need to create the same body for this request as you can see in the below wireshark screenshot. Start from line starting with “First boundary” and end till line starting with “Last boundary”. Please see the sample data below. I have removed all the extra fields from the body. Also, here “\r\n” means “new line”. Please take care of “\r\n”. See my final Jmeter request.

The below screenshot shows the ‘header’ that you need to add into the header manager (This should be the child of the HTTP sampler).

Finally, please see below the actual request in Jmeter.

Jmeter Request


Header Manager


Result – View results tree


The file that you want to upload should be present in the Jmeter/bin directory. If the location of the file is different, then you have to provide the full path in the request body.

2 comments:

  1. Hi, this can be used to upload a file in a JSF web app? thanks

    ReplyDelete
    Replies
    1. Sorry for the delayed response. I hope it should work fine for JSF web apps too.

      Let me know how it goes.

      Delete