This article demonstrates how to do a file upload with JMeter. This will show the steps when you have a load testing scenario where file upload is required.

Recording File Upload with JMeter

The simplest way of creating a JMeter test plan is recording the corresponding request using the HTTP(s) Test Script Recorder. JMeter acts as a proxy server, capturing all traffic between a web browser and the application under test (AUT), and converting it into the relevant HTTP requests.

JMeter has predefined templates which we can use to create test plans. Follow the steps below to set up JMeter for recording.

  1. Click on File → Templates and choose Recording Template.
  2. Click the Create button.
  3. Configure your browser to use the JMeter proxy by providing the IP address of the machine where JMeter is running as proxy server and proxy port.
  4. Open your HTTP(S) Test Script Recorder and click on the start button to start recording.

HTTP(S) Test Script Recorder

JMeter generate a certificate named “ApacheJMeterTemporaryRootCA.crt” file and stores it in the bin directory of JMeter. Install this certificate in your browser to capture HTTPS traffic. Now the setup is ready. Start performing your actions in a browser and JMeter captures the traffic and converts it to HTTP samplers as shown below.

Let’s take a look at the recorded request in the Test Plan:
HTTP Request

As you can see from the image above, JMeter correctly resolved the file name, which is index.html, but didn’t capture the full path to the file. This is a result of browser behaviour, as some browsers do not send the full path of the file which is being uploaded. That is why JMeter was not able to locate the file and send it along with the request.

By default, JMeter looks for index.html in its bin folder. If you run the recorded script, it will fail because the file is not present in bin folder of JMeter.

Script failed

The solution is to copy the file to the bin directory of JMeter. This way JMeter will pick up the file using the relative path and you’ll have a successful recording. Or you can give the absolute path in the HTTP sampler so that JMeter picks the file from the location specified from the HTTP sampler.

Absolute file path

Now if you run the script, JMeter picks the file from the absolute path and executes the HTTP sampler.

Successful results

Redline13 Load Testing Cloud with JMeter

JMeter is a strong and compelling tool to perform load testing. You can complement it with Redline13, which lets you simulate up to 1 million users in a single developer-friendly, self-service platform. For more information on running a JMeter test in RedLine13, follow this article.