# Request Body Update

**URL:** <https://community.postman.com/t/request-body-update/3126>\
**Category:** Help Hub\
**Tags:** request, local-files\
**Created:** [October 29, 2018, 10:58am UTC](https://community.postman.com/t/request-body-update/3126 "2018-10-29T10:58:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NehaM25](https://avatars.discourse-cdn.com/v4/letter/n/aeb1de/32.png) [@NehaM25](https://community.postman.com/u/NehaM25)\
**Post date:** [October 29, 2018, 10:58am UTC](https://community.postman.com/t/request-body-update/3126/1 "2018-10-29T10:58:50Z")

</div>

Hi ,  
I have scenario where I have some files converted to BAse64 format and I need to paste content in Request Body (Raw /Text) or Raw/JSON . These are huge in content.

Is there a way to do this via prerequisite script like passing file name or something. looking for passing file name as downthe line would like to parametrize this collection

---

<div class="post-metadata">

**Author:** ![payload-pilot-965338](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@payload-pilot-965338](https://community.postman.com/u/payload-pilot-965338)\
**Post date:** [January 17, 2023, 5:56pm UTC](https://community.postman.com/t/request-body-update/3126/2 "2023-01-17T17:56:59Z")

</div>

```auto
Yes, there is a way to include the content of a file in the request body of a Postman request using a pre-request script. Here is an example of how you can do this using JavaScript:

1. In your Postman request, select "Pre-request Script" from the "Tests" tab.
2. In the script editor, you can use the JavaScript `fs` (file system) module to read the file and get its content. For example, you can use the following code to read the file:

```

Preformatted textconst fs = require(‘fs’);  
const fileName = ‘path/to/file.txt’;  
const fileContent = fs.readFileSync(fileName, ‘utf8’);

```auto

3. To pass the content of the file as the request body, you can set the `pm.environment.set` method and set the value of the `fileContent` variable.

```

pm.environment.set(“fileContent”, fileContent);

```auto

4. In the request body select the "raw" and "text" option and type `{{fileContent}}`
5. You can parametrize this collection by using environment variables in the file path, so that you can change the file name dynamically at runtime.

```

const fileName = `path/to/${pm.environment.get("fileName")}`;

```auto

It's worth noting that this code assumes that the file is located on the same machine as the Postman application. If the file is located on a remote server, you will need to use a different approach to read the file, such as using the `http` module to make a request to the file's URL.

```

---

<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:** [January 18, 2023, 10:42am UTC](https://community.postman.com/t/request-body-update/3126/3 "2023-01-18T10:42:07Z")

</div>

@payload-pilot-965338

I can’t see the filesystem (fs) external library in the Postman JavaScript reference.

[Postman JavaScript reference | Using external libraries](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-external-libraries)

If I try and run this, I get “fs.readFileSync is not a function”.

Tried some of the other fs functions with similar results.

If I console.log(fs), I get an empty object instead of a function that you would normally get.

Do you have screenshots of this working?

Only asking as having the fs library available would be useful to have in the toolbox.

---

<div class="post-metadata">

**Author:** ![rb12121](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@rb12121](https://community.postman.com/u/rb12121)\
**Post date:** [October 4, 2023, 5:58am UTC](https://community.postman.com/t/request-body-update/3126/4 "2023-10-04T05:58:13Z")

</div>

> [@michaelderekjones](#):
>
> Only asking as having the fs library available would be useful to have in the toolbox.

I am facing the same issue. Please let me know if you find anything

---

<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:** [October 4, 2023, 9:27am UTC](https://community.postman.com/t/request-body-update/3126/5 "2023-10-04T09:27:56Z")

</div>

@rb12121

It’s not currently part of the sandbox, and I don’t think there are any plans for it to be.

However, you can use the Newman node.js libraries in conjunction with the filesystem libraries, but it means you need to know about about node and a decent level of JavaScript.

Here are some links and examples.

[newman - npm (npmjs.com)](https://www.npmjs.com/package/newman#using-newman-as-a-library)

[[Feature] possibility to programatically write to a file · Issue #3033 · postmanlabs/postman-app-support · GitHub](https://github.com/postmanlabs/postman-app-support/issues/3033)
