Example to execute a load test that will upload a file to the System Under Test(SUT).
Using the built-in function, open(), we are able to read the contents of a file given a filename or URL.
Below is a simple example showing how to load the contents of a local file data.json.
If you want to open a binary file you need to pass in "b" as the second argument.
Now that you know how to load a local file, let's look at a script that creates a POST request to upload this data to an API endpoint along with a regular text field (field in the example below):
In the example above we use the http.file() API to wrap the file contents in a FileData object. When passing a JS object as the body parameter to http.post(), or any of the other HTTP request functions, where one of the property values is a FileData a multipart request will be constructed and sent.