How to generate MD5 with the binary contents of file

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.

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 :slight_smile:

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

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.

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

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

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

I haven’t figured out a solution yet.

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.

1 Like