Unique file upload per iteration

I have a scenario where I want to upload different files for each post request,
but somehow I’m not able to do that as the open() function is not available inside the default function.

Hi @ializrocks,
You can’t open new files whenever and that is likely to stay the same due to the reason explained here. While there might be a possible API in the future that might make this more likely - there no such plans or open issues at the moment.

I would (as always) recommend trying load testing without having a different file per each post request and upping this to having for example 10 different files. And when that turns out to not be enough - then to try to build something that will be able to handle this better.

Depending on the use case I would recommend (in this order I guess):

  1. generating the files when needed . If the files that need to be uploaded is something you can generate in script - that likely will be the best option.
  2. getting the files from somewhere else - either having an http server that you jsut http.get them from before http.post them to the endpoitn you are testing or for example using something like xk6-redis and redis.
  3. build an extension to either generate, load or download the files the way you want.

Also of importance is the fact that uploading big files (where big isn’t well defined but lets go with above 1mb) isn’t well supported currently in k6.

You can see some (at this point dated, but likely still fairly accurate) experiment that shows what is needed to upload 26MB file and how much memory was this using up.

You can also take a look at this issue for some of the problems that will need to be fixed in order for this to be less of a problem.

1 Like

Hi @mstoykov, thanks for the suggestions