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 Data Uploads

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:

Hi Ned, I tried the above scenario but It did not work. Can you give any alternative solution for that. Thanks

Please explain how did it not work? What was the problem? Did you see an error or something?

I just tried the example locally and it seems to work for me, so I can’t help you unless you explain with some more words and/or screenshots exactly what the problem is.