Amazon S3 provides a set of API operations you can perform on Amazon S3 objects and for managing lifecycle configuration on a bucket. Out of these allowed operations, PUT and POST calls require passing of Content-MD5 in header of the request. AWS uses this as a message integrity check to verify that the data is the same data that was originally sent. There are different ways to generate this Content-MD5 value for the data you want to PUT or POST using the API.

Basic flow is: Data –>MD5 checksum (this is Hex output) –> Base64 encoding

Generating the Content-MD5 value using POSTMAN:

>>Add the below script statements in “Pre-request Script” of Postman

var md5checksum = CryptoJS.MD5(""+pm.request.body+"");
base64value = CryptoJS.enc.Base64.stringify(md5checksum);
postman.setGlobalVariable("contentMD5", base64value);

>>Make sure to add Global Variable “contentMD5” and assign it to Content-MD5 in header

>>This will generate the Content-MD5 value and save it in global variable “contentMD5”. Any data added to Body will be picked by the script to generate the md5 and then encoded to base64.

 

NOTE: The below two strings appear same but will generate different md5 checksum so be sure what you enter in POSTMAN request body is in correct format.

This is different

<LifecycleConfiguration><Rule><ID>deletefiles</ID><Filter><Prefix>testdoc</Prefix></Filter><Status>Enabled</Status><Expiration><Days>2</Days></Expiration></Rule></LifecycleConfiguration>

from

<LifecycleConfiguration>
   <Rule>
      <ID>deletefiles</ID>
      <Filter>
         <Prefix>testdoc</Prefix>
      </Filter>
      <Status>Enabled</Status>
      <Expiration>
         <Days>2</Days>
      </Expiration>
   </Rule>
</LifecycleConfiguration>