Skip to content

XAmzContentChecksumMismatch: The provided 'x-amz-checksum' header does not match what was computed.

0

Hi guys,

I have done a good deal amount of googling and asking around and yet to be able to upload a multipart file into AWS S3 without any issue. So what I want is fairly straightforward, upload a multipart file and check the data integrity with a FULL_OBJECT checksum check.

So I was facing the challenge of not knowing how I should generate the checksum which I already tackled it as described here. But now I am getting this weird looking error and IDK what I should do about it.

/home/kasir/projects/bugs/node_modules/.pnpm/@smithy+smithy-client@4.1.3/node_modules/@smithy/smithy-client/dist-cjs/index.js:867
  const response = new exceptionCtor({
                   ^
XAmzContentChecksumMismatch: The provided 'x-amz-checksum' header does not match what was computed.
    at throwDefaultError (/home/kasir/projects/bugs/node_modules/.pnpm/@smithy+smithy-client@4.1.3/node_modules/@smithy/smithy-client/dist-cjs/index.js:867:20)
    at /home/kasir/projects/bugs/node_modules/.pnpm/@smithy+smithy-client@4.1.3/node_modules/@smithy/smithy-client/dist-cjs/index.js:876:5
    at de_CommandError (/home/kasir/projects/bugs/node_modules/.pnpm/@aws-sdk+client-s3@3.744.0_aws-crt@1.25.3/node_modules/@aws-sdk/client-s3/dist-cjs/index.js:4970:14)
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/kasir/projects/bugs/node_modules/.pnpm/@smithy+middleware-serde@4.0.2/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
    at async /home/kasir/projects/bugs/node_modules/.pnpm/@aws-sdk+middleware-sdk-s3@3.744.0/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:483:18
    at async /home/kasir/projects/bugs/node_modules/.pnpm/@smithy+middleware-retry@4.0.4/node_modules/@smithy/middleware-retry/dist-cjs/index.js:321:38
    at async /home/kasir/projects/bugs/node_modules/.pnpm/@aws-sdk+middleware-sdk-s3@3.744.0/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:109:22
    at async /home/kasir/projects/bugs/node_modules/.pnpm/@aws-sdk+middleware-sdk-s3@3.744.0/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:136:14
    at async /home/kasir/projects/bugs/node_modules/.pnpm/@aws-sdk+middleware-logger@3.734.0/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22 {
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 400,
    requestId: '182453EC93EE9749',
    extendedRequestId: 'dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  Code: 'XAmzContentChecksumMismatch',
  Key: 'ea6ab51e-e651-4bd7-b3d4-9bcc96dd9309',
  BucketName: 'test',
  Resource: '/test/ea6ab51e-e651-4bd7-b3d4-9bcc96dd9309',
  RequestId: '182453EC93EE9749',
  HostId: 'dd9025bab4ad464b049177c95eb6ebf374d3b3fd1af9251148b658df7ac2e3e8'
}

BTW I am using Minio and Docker to test things in my local system, and use @aws-sdk/client-s3 npm library in NodeJS. Dunno if that may change things.

And here is my code and the problem kid is this part: https://github.com/kasir-barati/bugs/blob/122193cf7f55de909bc87b2da0af0e6d31f3a832/simplified.ts#L82-L83

  • Things are getting interesting, it seems like it does not matter if I say COMPOSITE or FULL_OBJECT. AWS will return the same checksum hash for my object. Look at this commit to understand what I mean.

  • New Findings

    So it seems there is a serious problem in AWS S3's API and with the current API we cannot actually pass the checksum of the entire object to the AWS. Currently I am looking around to see if I can get this to works somehow since this is very important in my case.

    https://github.com/aws/aws-sdk-js-v3/issues/6742#issuecomment-2547595379

asked 2 years ago4.3K views

3 Answers
0
Accepted Answer

So it turned out that this is an issue in Minio and as a matter of fact AWS S3 SDK is working like a charm if you're using CreateMultipartUploadCommand. For more info look at this closed issue in GitHub for @aws-sdk/client-s3: https://github.com/aws/aws-sdk-js-v3/issues/6888

And this open one at the moment of writing this answer: https://github.com/minio/minio/issues/20944

Hope this help somebody. BTW I appreciate it if you find this useful gimme a star on github.

answered 2 years ago

0

In your code in Github, you seem to be specifying the ChecksumAlgorithm parameter to UploadPart despite not wanting to use per-part checksums. You're also passing a ChecksumCRC32 property with the items in the CompletedPart[] array.

Since you're not wanting to use per-part checksums or composite checksums computed from them, I suggest you first remove both those references. Only leave the full-object checksum specifications in the calls to CreateMultipartUpload and CompleteMultipartUpload, and then test if the same or different error message is still being returned.

EXPERT

answered 2 years ago

  • Hi Leo and thanks for the reply. Actually the reason I've had to add that checksum is that when you specify a checksum algorithm in CreateMultipartUploadCommand you'll get a checksum for each part, even though I've just said that the checksum type should be FULL_OBJECT. I believe either this is a bug in AWS's SDK or the API as I've mentioned it here. I think I will open a new issue in AWS's SDK for Javascript to check if this is a real bug. BTW the latest changes to test what you've suggested are applied in this commit, lemme know if I missed something.

    And the error message changes to: InvalidPart: One or more of the specified parts could not be found. The part may not have been uploaded, or the specified entity tag may not match the part's entity tag. since AWS is expecting to receive a checksum for each part 🥲.

  • So I filed an issue in AWS SDK for NodeJS and I hope to get an answer soonish: https://github.com/aws/aws-sdk-js-v3/issues/6888

-2

The error you're encountering suggests that there's a mismatch between the checksum you're providing and the one calculated by the S3 service. This can happen for a few reasons when working with multipart uploads and checksums:

  1. Checksum calculation: Ensure that you're calculating the checksum correctly for the entire object, not just individual parts. For multipart uploads with a full object checksum, you need to calculate the checksum based on all the content of the multipart upload.

  2. Checksum algorithm: Make sure you're using a supported checksum algorithm for full object checksums in multipart uploads. Not all algorithms support full object checksums for multipart uploads. For example, SHA-256 and SHA-1 only support composite checksums for multipart uploads, while CRC32 and CRC32C support both full object and composite checksums.

  3. Checksum specification: When initiating the multipart upload, you need to specify the checksum algorithm you're using. Then, for each part upload, you should specify the same algorithm and provide the checksum calculated for that part.

  4. Completion: When completing the multipart upload, make sure you're providing all the necessary information, including the checksums for each part.

To resolve this issue:

  1. Double-check your checksum calculation to ensure it's correct for the entire object.
  2. Verify that you're using a supported checksum algorithm for full object checksums in multipart uploads (e.g., CRC32 or CRC32C).
  3. Make sure you're consistently specifying the checksum algorithm and providing checksums for each part of the upload.
  4. Review your code to ensure you're following the correct process for multipart uploads with checksums, including proper initiation, part uploads, and completion steps.

If you're still facing issues, you might want to try using a different checksum algorithm or consider using the S3 Transfer Manager, which can handle some of these complexities for you.
Sources
Checking object integrity in Amazon S3 - Amazon Simple Storage Service
Use checksums to work with an Amazon S3 object using an AWS SDK - Amazon Simple Storage Service
Use checksums to work with an Amazon S3 object using an AWS SDK - AWS SDK Code Examples

answered 2 years ago

  • I am not sure if you get what my question is, or at leas this is what AWS S3's doc says: "you can provide the checksum algorithm for the MultipartUpload API, simplifying your integrity validation tooling because you no longer need to track part boundaries for uploaded objects." this to me means that I do not need to send any checksum for the each part and rather I just need to send the entire object's checksum.

    When creating or performing a multipart upload, you can use full object checksums for validation on upload. This means that you can provide the checksum algorithm for the MultipartUpload API, simplifying your integrity validation tooling because you no longer need to track part boundaries for uploaded objects. You can provide the checksum of the whole object in the CompleteMultipartUpload request, along with the object size.

    When you provide a full object checksum during a multipart upload, the AWS SDK passes the checksum to Amazon S3, and S3 validates the object integrity server-side, comparing it to the received value. Then, Amazon S3 stores the object if the values match. If the two values don’t match, S3 fails the request with a BadDigest error. The checksum of your object is also stored in object metadata that you use later to validate an object's data integrity. — Ref.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.