For individual requests, you can simply set the body type to form-data
β, select a file, and send the request. Unfortunately, if youβre sending the same request as part of a Collection run, itβs a little more difficult than weβd like it to be at the moment. Thereβs an open feature request weβre working on to make it easier, but for now the recommended process is to use Newman , as follows:
In Postman, set the body type for your request to form-data
. Add a key, and select File
β as the type:
β
β
When youβre done working on your Collection, export it as a .JSON file so that it can be run with Newman
Open the Collection you exported as a .JSON file, and search for the form-data key you created for your file upload. Look for the "src"
property (it will be empty), and add the file path there:
{
"key":"your_key_here",
"type":"file",
"src": "" // <----- example: "src":"c:\\users\\files\\file.txt"
},
Please note that on Windows, youβll need to make all backslashes in the file path doubled (as shown above), so that the JSON parses correctly.
Install Newman (if you havenβt already)
Run the Collection using Newman
Please let us know if you have any additional questions, get stuck, or if you have suggestions on improvements!
1 Like
jdz100
(JD)
February 27, 2023, 11:36am
2
jdz100:
john-paul:
\\
I donβt think this works anymore. Newman isnβt giving any indications of a failed run:
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββ¬ββββββββββββββββββββββ
β β executed β failed β
βββββββββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββ€
β iterations β 1 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββ€
β requests β 1 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββ€
β test-scripts β 0 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββ€
β prerequest-scripts β 0 β 0 β
βββββββββββββββββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββ€
β assertions β 0 β 0 β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββ΄ββββββββββββββββββββββ€
β total run duration: 2s β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β total data received: 70B (approx) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β average response time: 1922ms [min: 1922ms, max: 1922ms, s.d.: 0Β΅s] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
But the photo Iβm trying to upload with newman using this method is not uploaded.
False alarm: the reason it didnβt work is because I didnβt allow Postman to use files outside of my working directory
When I moved the files to the working directory, it worked. It was just a bit frustrating that there was no informative error message so it took me ages to figure out.