Open sidoruka opened 2 months ago
According to the AWS doc: "A pre-calculated checksum value provided with the request disables automatic computation by the SDK and uses the provided value instead."
Let's look at this approach using as example CRC32
algorithm
<filepath>
that shall be uploaded to bucket <bucket>
via path <key>
Python3
import base64
import zlib
filepath = '<filepath>'
with open(filepath, 'rb') as f:
crc_raw = zlib.crc32(f.read())
crc_bytes = crc_raw.to_bytes(4, 'big')
crc_base64 = base64.b64encode(crc_bytes).decode('utf-8')
Python2
import base64
import zlib
import struct
filepath = '<filepath>'
with open(filepath, 'rb') as stream:
crc_raw = zlib.crc32(stream.read())
crc_bytes = struct.pack('>i', crc_raw)
crc_base64 = base64.b64encode(crc_bytes).decode('utf-8')
aws s3api put-object --bucket <bucket> --key <key> --checksum-crc32 "<crc_base64>" --body "<bucket>"
Response:
{
...,
"ChecksumCRC32": "<crc_base64>",
....
}
For example, to support it in pipe cli
we need to add header: 'x-amz-checksum-crc32': '<crc_base64>'
to put_object
request
aws s3api get-object-attributes --bucket <bucket> --key <key> --object-attributes Checksum
Response:
{
...,
"Checksum": {
"ChecksumCRC32": "<crc_base64>"
}
}
or using head object request
aws s3api get-object --bucket <bucket> --key <key> --checksum-mode=ENABLED
Upload:
Download:
pipe CLI shall be capable of:
--checksum-alg
option)Details: https://aws.amazon.com/blogs/aws/new-additional-checksum-algorithms-for-amazon-s3/