amazon-s3boto3pre-signed-url

Add automatic checksum to file uploaded using presigned post


I'm using the following code to generate the post url:

import boto3

client = boto3.client("s3", config=...)
presigned_post = client.generate_presigned_post(
        Bucket="my_bucket",
        Key="my_key",
        Fields={"x-amz-checksum-algorithm": "SHA1"},
        Conditions=[  # type: ignore
            {"x-amz-checksum-algorithm": "SHA1"},
        ],
    )

Then I upload to this url using for example web client:

const formData = new FormData()
const fields = uploadInfo.fields
Object.keys(fields).forEach((field) => {
  formData.append(field, get(fields, field))
})
formData.append('file', contents)
await fetch(uploadInfo.url, {method: "POST", body: formData})

However the uploaded file has no checksum in its properties. Not when I view it in s3 console nor in any api request.

Is it possible for the checksum to be calculated? I do see that etag is calculated, but that is an md5 checksum, while I need sha1.

The documentation at aws suggests this is possible, but the only examples are for post/put without presigned.

Also, I don't need the sha1 as a condition to the upload, I just want it as additional metadata for the uploaded content.


Solution

  • Apparently its silently not supported. From aws documentation:

    Currently, Amazon S3 presigned URLs don't support using the following data-integrity checksum algorithms (CRC32, CRC32C, SHA-1, SHA-256) when you upload objects. To verify the integrity of your object after uploading, you can provide an MD5 digest of the object when you upload it with a presigned URL.

    https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html