# Pre-request script: send multipart/form-data

**URL:** <https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763>\
**Category:** Help Hub\
**Tags:** pre-request-script\
**Created:** [May 15, 2021, 9:35am UTC](https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763 "2021-05-15T09:35:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikasreddyCapb](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vikasreddyCapb](https://community.postman.com/u/vikasreddyCapb)\
**Post date:** [May 15, 2021, 9:35am UTC](https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763/1 "2021-05-15T09:35:57Z")

</div>

I am trying to fetch a file from box & then upload it another server. This complete process is being done in pre-request script. I was able to successfully get the file buffer from box but I am struck at uploading the file to another server,as I need to send the data as formdata which needs multipart boundary.

If I use postman to upload file, then boundary is automatically calculated by postam. How to calculate/prepare multipart form-data in pre-request script?

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [May 15, 2021, 1:35pm UTC](https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763/2 "2021-05-15T13:35:51Z")

</div>

@vikasreddyCapb Welcome to the community 🥳

You can something like below:

```auto
const reqObj = {
    'method': 'POST',
    'url': 'https://postman-echo.com/post',
    'body': {
            'mode': 'formdata',
            'formdata': [
                {'key':'foo', 'value':'bar'},
                {'key':'bar', 'value':'foo'}
            ]
    }
};
pm.sendRequest(reqObj, (error, response) => {
    if (error) throw new Error(error);
    console.log(response.json());
});

```

Postman will add the headers for “multipart/form-data” 🙂

---

<div class="post-metadata">

**Author:** ![vikasreddyCapb](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vikasreddyCapb](https://community.postman.com/u/vikasreddyCapb)\
**Post date:** [May 16, 2021, 11:27am UTC](https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763/3 "2021-05-16T11:27:58Z")

</div>

@bpricilla Thanks for your reply.

Unfortunately, the provided solution did not work as there was an error ( **API upload did not contain a file part** ).

---

<div class="post-metadata">

**Author:** ![tom\_nbx](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@tom\_nbx](https://community.postman.com/u/tom_nbx)\
**Post date:** [November 30, 2022, 9:35am UTC](https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763/4 "2022-11-30T09:35:39Z")

</div>

Did you find a solution?

---

<div class="post-metadata">

**Author:** ![yannvr](https://avatars.discourse-cdn.com/v4/letter/y/d78d45/32.png) [@yannvr](https://community.postman.com/u/yannvr)\
**Post date:** [February 20, 2024, 11:18am UTC](https://community.postman.com/t/pre-request-script-send-multipart-form-data/23763/5 "2024-02-20T11:18:56Z")

</div>

The format looks like that:

```auto
  body: {
    mode: 'formdata', formdata: [
      {key: 'foo', value: 'foo'},
      {key: 'bar', value: 'bar'}
    ]
  }

```

There are additional optional props you can pass like so:

```auto
  body: {
    mode: 'formdata', formdata: [
      {key: 'foo', value: 'foo', disabled: false, description: {content:"", type:"text/plain"}},
      {key: 'bar', value: 'bar', disabled: false, description: {content:"", type:"text/plain"}}
    ]
  }

```
