# How to generate MD5 with the binary contents of file

**URL:** <https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463>\
**Category:** Help Hub\
**Created:** [May 6, 2021, 9:26am UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463 "2021-05-06T09:26:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayajaya](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jayajaya](https://community.postman.com/u/jayajaya)\
**Post date:** [May 6, 2021, 9:26am UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/1 "2021-05-06T09:26:46Z")

</div>

_My question_:  
While uploading a file , a MD5 hash is generated with the binary contents of the file and this MD5 is sent to server to obtain a token. With this token actually file upload happens.

How do I generate MD5 with the binary of the file. I am using CryptoJS.MD5(binary).toString(); to get the MD5 hash in Pre request script. However i am unable to figure out how to pass the binary content of the file.

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [May 8, 2021, 5:16pm UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/2 "2021-05-08T17:16:14Z")

</div>

Hi @jayajaya,

Once you have generated the MDS hash from the contents in the pre-requisite script. You can assign the value to the global or environment variable and use the same in body of the request, which will reflect.

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![jayajaya](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jayajaya](https://community.postman.com/u/jayajaya)\
**Post date:** [May 10, 2021, 4:44pm UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/3 "2021-05-10T16:44:17Z")

</div>

Hi @pranavdavar , thanks for your response . My questions is I have a file I would like to generate MD5 with the contents of the file. How do i do it?

Thanks  
Jayashree

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [May 13, 2021, 12:20pm UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/4 "2021-05-13T12:20:22Z")

</div>

Hi @jayajaya,

You can try using base64 encoded binary content of the file and then pass it by decoding as input to CryptoJS.MD5(binary). By this, you will be able to generate the MD5 token.

---

<div class="post-metadata">

**Author:** ![jayajaya](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jayajaya](https://community.postman.com/u/jayajaya)\
**Post date:** [May 18, 2021, 8:38am UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/5 "2021-05-18T08:38:23Z")

</div>

Hi @pranavdavar ,  
I have to dynamically do it for different files instead of just passing base64 encoded binary content of the file into a variable. Do you have an idea of how it can be done ?

Thanks  
Jayashree

---

<div class="post-metadata">

**Author:** ![SherifAhmedMahmoud](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@SherifAhmedMahmoud](https://community.postman.com/u/SherifAhmedMahmoud)\
**Post date:** [July 12, 2021, 8:12am UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/6 "2021-07-12T08:12:02Z")

</div>

Did you found any solution for this? I have the same issue how to get the binary file content in pre script.

Thanks  
Sherif Ahmed

---

<div class="post-metadata">

**Author:** ![lucashugdahl](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/lucashugdahl/32/9831_2.png) [@lucashugdahl](https://community.postman.com/u/lucashugdahl)\
**Post date:** [September 22, 2021, 11:54pm UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/7 "2021-09-22T23:54:43Z")

</div>

Has anyone figured out how to read the contents of an attached file yet?

---

<div class="post-metadata">

**Author:** ![jayajaya](https://avatars.discourse-cdn.com/v4/letter/j/c4cdca/32.png) [@jayajaya](https://community.postman.com/u/jayajaya)\
**Post date:** [September 23, 2021, 8:12am UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/8 "2021-09-23T08:12:38Z")

</div>

I haven’t figured out a solution yet.

---

<div class="post-metadata">

**Author:** ![apullin](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@apullin](https://community.postman.com/u/apullin)\
**Post date:** [November 11, 2021, 4:15am UTC](https://community.postman.com/t/how-to-generate-md5-with-the-binary-contents-of-file/23463/9 "2021-11-11T04:15:42Z")

</div>

Pretty unfortunate that this is not available as a feature. There are several threads about it.

For the case that a file is to be used as the body, it looks like the pre-request script apparently only receives a JS object indicating that the “mode” is “file” and the filename to be loaded and provided as the body.
