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.
Suppose you want to test an API that can add users to the system using a CSV file.
K6 provides detailed documentation that shows how you can create an API request to perform the upload function.
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…