Skip to content
  • ZipCode Api
  • Blog
  • About RedLine13
RedLine13
RedLine13
Primary Navigation Menu
Menu
  • Start Testing
  • Demo
  • Pricing
  • JMeter
  • Partners
  • Docs
    • Documentation Home
    • AWS Set Up for load testing
    • AWS Approval for Large Tests
    • PHP, NodeJS, Python Load Tests
    • Scalability
    • Jenkins Plugin Setup
    • Premium Features
    • Knowledge Base

JMeter Testing Multiple Random File Uploads – Updated

By: RedLine13

This is one of our most popular blog posts – File Uploads. Check out a new section #3: Adding Parameters to your HTTP Request. Read below for lots of great information.

There are many cases of testing performance of API Endpoints for file uploads. We chose to demonstrate scaling out such a test building our load test plan in JMeter. JMeter supports file uploads natively within the HTTP Request, and Redline13 supports attaching files to your test plan. However, user uploads are random, so we need to generate files sized from 10,000 to 100,000 characters.

1. Load Plan

We wanted each load agent to simulate 60 users, each user loading 20 photos of random size.

Screen Shot 2015-02-10 at 12.41.08 AM

2. Create HTTP Request Defaults and HTTP Request for File Uploads

The Request Default is your standard setup of Server Name.

Within the HTTP Request, we can configure our File Upload from variables.

In the ‘Send Files with Request’ section, we set

  • File Path to be a variable ${filename}
  • Parameter Name to the variable name the server side expects

Screen Shot 2015-02-10 at 12.48.11 AM

3. Adding Parameters to your HTTP Request

In many cases, we need to send additional parameters alongside the file to be uploaded. In order to do this we need to click “Use multipart/form-data” option.

Additional parameters for file uploads

It is not mandatory to specify the “Content Type” but it is a good practice. Fill in the “MIME Type” field to specify what type of a file we are sending . In our example we are sending a simple text file and we write a “text/plain” on this field. If you were uploading an image with png format you would use “image/png” as the MIME Type.

4. Generate Random Files in Pre-Processor

To achieve this for each request, we used the ‘Bean Shell PreProcessor‘ with the following code snippet

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;

// Create a temp file
File myFile = File.createTempFile("upload-", "" );

// Generate Random length string and write to file
FileUtils.writeStringToFile(myFile, RandomStringUtils.random( RandomUtils.nextInt( 1000, 100000 ) ), "UTF-8" );

// Store file name in variable.
vars.put( "filename", myFile.getCanonicalPath() );

Screen Shot 2015-02-10 at 12.52.21 AM

5. Clean Up Files in Post Processor

Clean up is a pretty simple task.


import org.apache.commons.io.FileUtils;
// Delete file and do not throw error
FileUtils.deleteQuietly(new File( vars.get("filename")));

6. Example Test and JMX File Uploads

Here is an example 4 Server test executing almost 5,000 uploads under 5 minutes.

Screen Shot 2015-02-10 at 12.55.57 AM

You can now download the JMX file and browse the results at File Upload Test Plan. With RedLine13, you can run a JMeter Load Test with your JMX script of any mobile application, web application, or API.

You can run your own test with file uploads on RedLine13 for free.

2019-09-11
Previous Post: RedLine13 UI Update: RedLine13 Graphs
Next Post: Advanced Load Testing Troubleshooting – the Case of the Last Minute Spike

Recent Posts

  • JMeter XML Format Post Processor
  • Order of Elements in JMeter
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener

Related

  • JMeter XML Format Post Processor
  • Order of Elements in JMeter
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener
  • Using Test Fragments in JMeter Tests
  • Step-by-Step Guide to Testing with JMeter
  • Functional Testing vs Performance Testing
  • A Gentle Introduction to Load Testing
  • Using the JMeter Counter Element

© RedLine13, LLC | Privacy Policy | Contract
Contact Us: info@redline13.com

Designed using Responsive Brix. Powered by WordPress.