# Post request - to upload a lot of files but only one at a time

**URL:** <https://community.postman.com/t/post-request-to-upload-a-lot-of-files-but-only-one-at-a-time/71275>\
**Category:** Help Hub\
**Tags:** variables, form-data, post, file, uploads\
**Created:** [November 15, 2024, 11:24am UTC](https://community.postman.com/t/post-request-to-upload-a-lot-of-files-but-only-one-at-a-time/71275 "2024-11-15T11:24:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacecraft-explore14](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@spacecraft-explore14](https://community.postman.com/u/spacecraft-explore14)\
**Post date:** [November 15, 2024, 11:24am UTC](https://community.postman.com/t/post-request-to-upload-a-lot-of-files-but-only-one-at-a-time/71275/1 "2024-11-15T11:24:41Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/9/19ca9d7a598aafc6bcc8f3eb810cdfc051b3a6e0.png)

I use mac Intel. And Postman (free) version is:  
Version 11.18.1  
UI Version: 11.18.1-ui-241029-1240  
Desktop Platform Version: 11.18.0 (11.18.0)

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 15, 2024, 1:23pm UTC](https://community.postman.com/t/post-request-to-upload-a-lot-of-files-but-only-one-at-a-time/71275/2 "2024-11-15T13:23:11Z")

</div>

Have a look at the following topic on Stack Overflow.

[Can Postman take a file as a variable from a path? - Stack Overflow](https://stackoverflow.com/questions/63121276/can-postman-take-a-file-as-a-variable-from-a-path)

I can see two potentials solutions here.

This one.

[https://stackoverflow.com/a/64954126/22769054](https://stackoverflow.com/a/64954126/22769054)

But I actually prefer this one as it doesn’t require you to hack the collection JSON.

[https://stackoverflow.com/a/74832159/22769054](https://stackoverflow.com/a/74832159/22769054)

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)

```auto
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
}; 

```

---

<div class="post-metadata">

**Author:** ![spacecraft-explore14](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@spacecraft-explore14](https://community.postman.com/u/spacecraft-explore14)\
**Post date:** [November 15, 2024, 2:03pm UTC](https://community.postman.com/t/post-request-to-upload-a-lot-of-files-but-only-one-at-a-time/71275/3 "2024-11-15T14:03:25Z")

</div>

> [@michaelderekjones](#):
>
> ```auto
> 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

---

<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 15, 2024, 2:04pm UTC](https://community.postman.com/t/post-request-to-upload-a-lot-of-files-but-only-one-at-a-time/71275/4 "2024-12-15T14:04:10Z")

</div>

Closed on December 15, 2024, 2:04pm UTC

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