Hi
i have a k6 script that reads two images and send them to a .net core API, the script is:
import http from "k6/http";
const path = "path/image1";
const path2 = "path/image2";
const image1Byte = open(path, "b");
const image2Byte = open(path2, "b");
const image1Name = "image1.jpeg";
const image2Name = "image2.jpeg";
export default function () {
try {
console.log("Start");
sendFiles();
console.log("Finish");
} catch (error) {
console.error(error);
return null;
}
}
async function sendFiles() {
const url = "path/to/server";
const image1 = http.file(image1Byte , image1Name );
const image2 = http.file(image2Byte , image2Name );
const files = [];
files.push(image1);
files.push(image2);
let response = http.post(url,{files});
return response;
}
the API that receives the request is:
[HttpPost]
[Route("PostFiles")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public virtual async Task<ActionResult<Dictionary<string, long>>> PostFiles([FromForm] List<IFormFile> files)
in the above case the request is caught at the api, but files
at the API is always has count of 0, although if i send only one image to the API such as:
const files = image1
it reaches the API correct and i can read its data of the image1, what I’m doing wrong here? keep in mind that in both cases the request reaches the API but in list case the parameter files is empty