Knowledgebase

Load Testing Data Uploads


Background

Scripting examples on how to execute a load test that will upload a file to the System Under Test(SUT).


Uploads

Binary file upload

1
2
3
4
5
6
7
8
9
10
11
12
import http from "k6/http";
import { sleep } from "k6";

let binFile = open("/path/to/file.bin", "b");

export default function() {
  var data = {
    file: http.file(binFile, "test.bin")
  };
  var res = http.post("https://example.com/upload", data);
  sleep(3);
}

Relevant k6 APIs:

Creating a multipart request

With multipart requests you combine pieces of data with possibly different content types into one request body. A common scenario is for example a form with regular text input fields and a file field for uploading a file:

1
2
3
4
5
6
7
8
9
10
11
12
13
import http from "k6/http";
import { sleep } from "k6";

let file = open("/path/to/file.txt");

export default function() {
  var data = {
    field: "this is a standard form field",
    file: http.file(file, "test.txt")
  };
  var res = http.post("https://example.com/upload", data);
  sleep(3);
}

Relevant k6 APIs: