How can I check the integrity of an object uploaded to Amazon S3?
"I want to upload an object to an Amazon Simple Storage Service (Amazon S3) bucket. Additionally, I want to verify the integrity of the uploaded object. How can I do that?"
"I want to upload an object to an Amazon Simple Storage Service (Amazon S3) bucket. Additionally, I want to verify the integrity of the uploaded object. How can I do that?Short descriptionFollow these steps to verify the integrity of uploaded objects using the Content-MD5 header:Note: When you use the Content-MD5 header, Amazon S3 checks the object against the provided Content-MD5 value. If the values do not match, you receive an error.1.    Calculate the Content-MD5 value of the object.2.    Verify the integrity of the uploaded object by passing the Content-MD5 value as a request header during the object upload.ResolutionCalculate the Content-MD5 value of the objectWindows OSIf you're using a Windows operating system, you can use the Get-FileHash cmdlet from Microsoft PowerShell Utility to calculate MD5 digest, like this:Get-FileHash \path\to\file -algorithm MD5 | Format-ListNote: The Get-FileHash cmdlet is available with Microsoft PowerShell Utility version 4.0 and later.Here's an example output:Algorithm : MD5Hash      : C9A5A6878D97B48CC965C1E41859F034Path      : \path\to\fileThen, apply base64-encoding to the calculated MD5 digest to get the required Content-MD5 value:$hashString ='C9A5A6878D97B48CC965C1E41859F034'$hashByteArray = [byte[]] ($hashString -replace '..', '0x$&,' -split ',' -ne '')$ContentMD5 = [System.Convert]::ToBase64String($hashByteArray)Echo $ContentMD5yaWmh42XtIzJZcHkGFnwNA==In this example, the output of Echo $ContentMD5, ("yaWmh42XtIzJZcHkGFnwNA=="), is the required Content-MD5 value.Linux OSIf you're using a Linux operating system, run the following OpenSSL command to obtain the Content-MD5 value of your file:openssl md5 -binary PATH/TO/FILE | base64Verify the integrity of the uploaded objectWhen you use PutObject to upload objects to Amazon S3, pass the Content-MD5 value as a request header. Amazon S3 checks the object against the provided Content-MD5 value. If the values do not match, you receive an error.The Content-MD5 request header can also be used with the S3 UploadPart API.Related informationCommon request headersS3 error responsesFollow"