Hi Community! I have the next challenge: I need to create a collection where I need to upload a lot of files. Important here that it should be one file at a time (not bulk upload). My idea was to use a variable in “form-data” with file type, but it is impossible to set a variable there. Is that a supported feature? Or it is not?
You are basically overwriting the body in the pre-request script.
You would read the file name from your CSV or JSON data file. Then retrieve the file name for the current iteration and then overwrite the body.
Something like… (untested)
let src = pm.variables.get("fileName"); // Get file name from data file - needs to match the relevant column header or JSON key
pm.request.body.mode = "formdata";
pm.request.body.formdata = {
"key": "file", // or change to your prefered key name
"type": "file",
"src": src
};
Thanks Mike! You are fantastic!
I also tried the first solution and it worked but I had doubts as it is a hack.
The second option looks more correct.
Thank you for your additional comments as well! they make a lot of sense