I have a problem with k6 file upload. By the way formData.body() returns [object ArrayBuffer] in the console
Taking 500 error which inclues below;
"code":500,"applicationErrorCode":-1,"message":"Unknown Error","exceptionContent":"System.NullReferenceException: Object reference not set to an instance of an object.\n
My code below;
import { describe } from "https://jslib.k6.io/expect/0.0.4/index.js";
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';
import exec from "k6/execution";
import { check } from 'k6';
import http from "k6/http";
import Load, { Roles } from "../../../core/load.js";
let endpoints = JSON.parse(open("../../../core/endpoint.json"));
let file = open('../../../utils/waybill.jpg','b')
export function setup() {
let supportAuth = Load.auth(Roles.Support);
let waysSeedRes = http.post(
Load.api + endpoints.Debug.Seed + '?seeds=Ways',
{
headers: {
Authorization: `Bearer ${supportAuth.json().access_token}`,
"Content-Type": "application/json",
apikey: "test"
}
}
);
return [
supportAuth.json(),
waysSeedRes .json()
];
}
const totalVu = 1;
export const options = {
summaryTimeUnit: "ms",
scenarios: {
Ways: {
exec: "Ways",
executor: "per-vu-iterations",
vus: totalVu,
iterations: 1,
},
},
};
export function Ways(data) {
let tokenForSupport = data[0].access_token;
describe("Ways scenerio", (t) => {
const formData = new FormData()
formData.append('file', file)
const res = http.post(Load.api + endpoints.Waybills.uploadWaybillImage, formData.body(), {
headers: {
Authorization: `Bearer ${tokenForSupport}`,
apikey: "test",
'Content-Type': 'multipart/form-data'
},
});
console.log("fileUpload",res.body)
check(res, {
'is status 200': (r) => r.status === 200,
});
});
}