Load testing for upload file APIs using k6

When working with APIs, sometimes we need to test the APIs that are used for uploading data to the system via files. In this blog, let’s see how you can perform load testing for those kinds of APIs using k6.

Donald Le
2 min readApr 4, 2024
Photo by Gatis Marcinkevics on Unsplash

Suppose you want to test an API that can add users to the system using a CSV file.

API request for upload user API with Postman

K6 provides detailed documentation that shows how you can create an API request to perform the upload function.

k6 detailed documentation for uploaded-data testing

Below is a snippet code for constructing the http request for the upload/person API that takes a CSV file as an uploaded file.

export async function uploadUsers(domain, csvFile){
let url = domain + '/upload/users';
const fd = new FormData();
fd.append('csv', http.file(csvFile, 'file.csv', 'text/csv'));

return http.asyncRequest('POST', url, fd.body(), {
headers: { 'Content-Type': 'multipart/form-data…

--

--

Donald Le
Donald Le

Written by Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

No responses yet