Upload Content to API

I am trying to upload file (excel {xlsx}) to an API using k6.

I am using the K6 script
k6>process.js
this script call an api (Asp.net core API (5.0)).
The file(s) are uploaded but file uploaded file(s) are not correct.

To reproduce :

  1. Clone Repository (GitHub - HiteshDutt/K6ContentUpload), Checkout branch main
  2. In Directory API, open solution FileUpload.sln
  3. Run the project (web API) to expose endpoint.
  4. Navigate to main parent directory and change directory to k6
  5. in k6 directory please run process.js script using k6 run ./process.js
  6. uploaded files are found in API>FileUpload>Recources>Images

Using POSTMAN to upload files using the same endpoint works as expected. Please find postman export under directory name PostMan.
The Post action is used to send content of excel as binary data.

Seeking help to fix k6 script to upload the file.

Hi @hidutt. welcome the forum!

Thanks for the repo!

You wrapping the body in http.file means that it will make the body to be a multipart-form which is what you then dump to the file. You should just fileContent as the body.

edit: I have made you a PR with both the “fix” and a Dockerfile I needed to make so I can test it.

1 Like

Amazing. This works :slightly_smiling_face:

I am sure this would be part of any documentation but I could not find it.

Thanks for your quick support and help.