# How to validate existance of a file using postman script?

**URL:** <https://community.postman.com/t/how-to-validate-existance-of-a-file-using-postman-script/7470>\
**Category:** Help Hub\
**Tags:** scripts, file\
**Created:** [August 28, 2019, 5:05am UTC](https://community.postman.com/t/how-to-validate-existance-of-a-file-using-postman-script/7470 "2019-08-28T05:05:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhikum28](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@abhikum28](https://community.postman.com/u/abhikum28)\
**Post date:** [August 28, 2019, 5:05am UTC](https://community.postman.com/t/how-to-validate-existance-of-a-file-using-postman-script/7470/1 "2019-08-28T05:05:47Z")

</div>

I am testing a API which returns response and for authenticated user along with that also download a file in local. I want to validate that whether the file is downloaded. I have tried  
with Postman script using new File("/data/file/abc.json") and new ActiveXObject(“Scripting.FileSystemObject”) but not able to do it.

var testFile= new File("/data/file/abc.json");

if(TestFile.exists()){  
console.log(‘The file exists’);  
}else{  
console.log(‘The file does not exist’);  
}

I am getting error ReferenceError: File is not defined

---

<div class="post-metadata">

**Author:** ![amit](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/amit/32/2056_2.png) [@amit](https://community.postman.com/u/amit)\
**Post date:** [August 28, 2019, 5:25am UTC](https://community.postman.com/t/how-to-validate-existance-of-a-file-using-postman-script/7470/2 "2019-08-28T05:25:47Z")

</div>

**Postman doesn’t provide entire Node modules for scripts**

For security purposes, Postman uses a sandbox script execution environment

- [https://learning.getpostman.com/docs/postman/scripts/postman\_sandbox](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox)

Modules available within this Sandbox are listed here

- [https://learning.getpostman.com/docs/postman/scripts/postman\_sandbox\_api\_reference](https://learning.getpostman.com/docs/postman/scripts/postman_sandbox_api_reference)

**For the usecase you are trying to solve**  
You should get the file’s content as part of the API response when invoking the API via Postman.

You may then look for `Content-Disposition` header within the test script

_Example Header:_

```
Content-Disposition: attachment; filename="somename.json"

```

For your reference: [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)

By checking the header value you can see what the filename is.  
And if you want to check the file’s content it should be part of the response body.

_Example Postman test script:_

```
pm.test("Content-Disposition is set", function () {
    pm.response.to.have.header("Content-Disposition", "attachment; filename=\"somename.json\"");
});
```

---

<div class="post-metadata">

**Author:** ![abhikum28](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@abhikum28](https://community.postman.com/u/abhikum28)\
**Post date:** [August 28, 2019, 7:00am UTC](https://community.postman.com/t/how-to-validate-existance-of-a-file-using-postman-script/7470/3 "2019-08-28T07:00:14Z")

</div>

Thanks Amit for your reply. I am new to Postman and started using it just few days back.  
Let me try and I’ll come back to you if need more information on this. 🙂
