# Upload a File - while running the collection (you need not mention any static location/file, instead you can upload the file(s) from desired location)

**URL:** <https://community.postman.com/t/upload-a-file-while-running-the-collection-you-need-not-mention-any-static-location-file-instead-you-can-upload-the-file-s-from-desired-location/38978>\
**Category:** Help Hub\
**Created:** [September 9, 2022, 6:03am UTC](https://community.postman.com/t/upload-a-file-while-running-the-collection-you-need-not-mention-any-static-location-file-instead-you-can-upload-the-file-s-from-desired-location/38978 "2022-09-09T06:03:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madhu.Gonthina](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/madhu.gonthina/32/13175_2.png) [@Madhu.Gonthina](https://community.postman.com/u/Madhu.Gonthina)\
**Post date:** [September 9, 2022, 6:03am UTC](https://community.postman.com/t/upload-a-file-while-running-the-collection-you-need-not-mention-any-static-location-file-instead-you-can-upload-the-file-s-from-desired-location/38978/1 "2022-09-09T06:03:54Z")

</div>

1. Place the files you want to upload in a location.

2. Create a csv data file ( file.csv ) and place the file names you want to upload as shown below

![Files](https://us1.discourse-cdn.com/getpostman/original/2X/3/3635fff93b14adae5b6c628e58bc921fada82187.jpeg)

1. In your Pre-request script, add set a variable as shown below

pm.environment.set(“filepath”,data.\_filepath);

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/a/aa248021a930634bd09f27ff53073edb21f72c1b.png)

1. Open your collection.json file and you will find the below formdata where you have selected the file location as shown below

“method”: “POST”,  
“header”: ,  
“body”: {  
“mode”: “formdata”,  
“formdata”: [  
{  
“key”: “File”,  
“type”: “file”,  
**“src”: “/C:/here/prod.json”**  
}

here, modify **“src”: “/C:/here/prod.json”** to **“src”: “{{filepath}}”**

1. Now navigate to the path where you have the files and want to upload. So, in my case I navigated to **C:\here** and launched cmd from here and executed below command.

newman run --insecure \<collection\_path\>\Products.postman\_collection.json -d \file.csv -r htmlextra --reporter-htmlextra-export “\<Report\_path\>\Fileupload.html” --reporter-htmlextra-title “\<Report\_Name\>”

Now my test will run with two iteration as shown below

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/d/db0b15cb21776f1dd51fa626f23f91d0d9869dc5.png)

Iteration1 - you will find the Request body as

{  
“File”: “prod.json”  
}

Iteration2 - you will find the Request body as

{  
“File”: “str.json”  
}

Hope, this solution helps us in not selecting a static file and upload all the desired files from selected location

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 2:46pm UTC](https://community.postman.com/t/upload-a-file-while-running-the-collection-you-need-not-mention-any-static-location-file-instead-you-can-upload-the-file-s-from-desired-location/38978/2 "2024-12-12T14:46:57Z")

</div>

Closed on December 12, 2024, 2:46pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
