How to make the following multipart/form-data requests in k6

able to make mulpart/form-data request using http.file() API successfully, but not the following requests.

Please help me how to make the following multipart/form-data requests in k6.

Request#1
content:

test


forumId: e4a3d7ab-078f-11eb-aa5d-06340f9ea8b8
isDraft: false

Request#2
attachments[0].description:
attachments[0].file: http.file(binFile, “test.bin”)
attachments[0].kind: file
content:
forumId: e4a3d7ab-078f-11eb-aa5d-06340f9ea8b8
isDraft: true

I am not sure I completely understand the question, but take a look at https://k6.io/docs/examples/data-uploads#multipart-request-uploading-a-file

Your second request should look somewhat like this:

import http from 'k6/http';
import { sleep } from 'k6';

let binFile = open('./image.png', 'b');

export default function () {
    var data = {
        'attachments[0].description': 'foo',
        'attachments[0].file': http.file(binFile, 'test.bin'),
        'attachments[0].kind': 'file',
        'content': 'bar',
        'forumId': 'e4a3d7ab-078f-11eb-aa5d-06340f9ea8b8',
        'isDraft': 'true',
    };

    var response = http.post('https://httpbin.test.k6.io/anything', data);

    console.log(response.body);
}

I have tried your solution, but it doesn’t work.

I’d need more details in order to help you… Specifically, how doesn’t it work? :wink: