Below is the example of my postman equivalent curl
curl --location 'http://my-service/v3/legacy/import?family=WGeneric' \
--header 'X-TRS-AUTH-PERMS: {{auth_perms}}' \
--header 'X-Trs-Auth-Alias: {{auth_alias}}' \
--header 'X-APIKEY: <qwertyuiopasdfghjkl;>' \
--form 'file=@"/Users/xx/load-test/scripts/files/data.xls"'
output:
{
"msg": "File successfully uploaded and submitted to avdownload",
"sha256": "sdfghjksdfgh5678dhkhfkdsfdsfdsf",
"success": true
}
Below is my k6 code, (I have put only the relevent part)
const filePath = '/Users/xx/load-test/scripts/files/data.xls';
// Read the file content during the initialization phase
const fileContent = open(filePath);
if (!fileContent) {
console.error(`Error reading file content from ${filePath}`);
// Abort the test or handle the error as needed
}
export default function () {
const apikey = __ENV.API_KEY;
const headers = {
'X-APIKEY': apikey,
};
const response = http.request( "POST", baseURL, fileContent, {
headers: headers,
});
check(response, {
'status is 200': (r) => r.status === 200,
});
console.log(`Request URL: ${baseURL}`);
console.log(`Request Headers: ${JSON.stringify(headers)}`);
console.log(`Response Status Code: ${response.status}`);
console.log(`Response Body: ${response.body}`);
sleep(1);
}
the output of logs would be
INFO[0027] Response Status Code: 400 source=console
INFO[0027] Response Body: {"@status":"error","code":400.......}