I am trying to create a predesigned POST request using the AWS Javascript SDK for S3, using the method createPresignedPost. The idea is to generate the URL and fields which should be used in a multipart form request, to upload a file to a protected S3 bucket. I would like to include checksum verification (whereby I pass in the expected SHA256 checksum of the file to the presigner, and the S3 server verifies that the checksum of the uploaded file corresponds to the one provided, so that only the originally specified file may be uploaded using this request) as well as to restrict the size of the upload. I originally tried to follow this tutorial which seemed pretty comprehensive. However, this did not work (I kept on getting an error regarding the Content-MD5 header) and I eventually found that MD5 does not seem to be supported by S3 anymore. I also noticed that the presigner was including the field X-Amz-Algorithm=AWS4-HMAC-SHA256 which would seem to indicate that it is defaulting to SHA-256. However, sending the SHA256 hash with the same request did not solve the problem nor could I find any explicit way to tell the presigner which algorithm to use and what value to expect. I cannot remember where I came across it, but I tried including:
{ ChecksumAlgorithm: ChecksumAlgorithm.SHA256 }, { ChecksumSHA256: hash }, in my conditions but this did not work either. I am not sure whether I am understanding this issue correctly, but it may even be that S3 does not support checksum verification for presigned POST.
So, I suppose my questions come down to the following:
- does S3 support checksum verification on presigned
POST? - does the AWS Javascript SDK support adding the parameters required for checksum verification on presigned
POST(and if so, in which version)? - does the AWS Javascript SDK support specifying the algorithm to use for checksum verification?
- does anyone have an example of code using the AWS Javascript SDK to generate the URL and fields for a presigned
POST, restricting the uploaded file to correspond to the given checksum value?
content-length-rangeallowing you to specify a minimum and maximum file size. This does not mention the use of a lambda anywhere. The lambda provided by Fedi takes care of validating the checksum of the file. And indeed, I am explicitly asking multiple questions in the one post (indicated by the numbering), although a reply to the final question would be an answer to all 4 questions.