- Newest
- Most votes
- Most comments
Amazon S3 supports automatic checksum calculation for data integrity validation during uploads, including SHA-256. To achieve what you're trying to do, you need to make a few adjustments to your approach.
When generating a presigned URL with checksum validation, you need to ensure that the checksum is included as part of the signature calculation. This means the client must include the same checksum when uploading the file.
For your specific use case, you have two main options:
-
Use Content-MD5 header validation: When generating the presigned URL, include the Content-MD5 header in the signed headers. This will require the client to provide the correct MD5 checksum when uploading, and S3 will reject uploads with mismatched checksums.
-
Use the ChecksumSHA256 parameter correctly: When you include ChecksumSHA256 in your PutObjectCommand, you're telling S3 to expect this checksum in the upload. However, the client must also include this same checksum in the
x-amz-checksum-sha256header when uploading.
To make the second approach work:
- When generating the presigned URL, make sure to include
x-amz-checksum-sha256in the list of signed headers - The client must include the same base64-encoded SHA-256 checksum in the
x-amz-checksum-sha256header when uploading
After a successful upload, you can retrieve the stored SHA-256 checksum using the GetObjectAttributes or HeadObject operations. The checksum will be available in the object's metadata, and you can compare it with your database value.
If you're still having issues, ensure that:
- The SHA-256 checksum is properly base64 encoded (not hex encoded)
- The
x-amz-checksum-sha256header is included in the signed headers list - The client is correctly including this header with the exact same value when uploading
This approach will ensure that S3 validates the integrity of the uploaded file against the expected SHA-256 checksum, and will reject uploads that don't match.
Sources
Checking object integrity for data uploads in Amazon S3 - Amazon Simple Storage Service
Securing Amazon S3 presigned URLs for serverless applications | AWS Compute Blog
How do I calculate an AWS S3 compatible SHA-256 hash from a Blob in Angular? | AWS re:Post
Relevant content
asked 4 years ago
- AWS OFFICIALUpdated 3 months ago

I am facing the exact same problem. I have added the checksum algorithm and computed the checksum in the presigned URL generation request. When I upload the file with the header x-amz-checksum-sha256, it throws the error: "There were headers present in the request which were not signed".
s3.PutObjectInput{ Bucket: &bucket, Key: &key, Body: bytes.NewReader(fileData), ChecksumAlgorithm: types.ChecksumAlgorithmSha256,
the problem i am trying to solve is , to get the checksum in the headers when I will download from the url