Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does S3 ETag have extra characters?

Tags:

I uploaded a file with aws cli using s3api put-object and the response is like this:

{
    "ETag": "\"7bd173e5150f57f8ffe94ad61cd5ea9d\""
}

When I calculate the hash locally with md5 I get this:

173e5150f57f8ffe94ad61cd5ea9d

Why does the ETag have 3 extra characters at the front? This is a small file (8KB) so it's a single part upload.

like image 518
Elliott B Avatar asked Dec 17 '19 22:12

Elliott B


People also ask

Is ETag in S3 unique?

Files uploaded to Amazon S3 using the S3 multipart API will have unique ETag values depending on their contents and the chunk size used to upload the file.

What is the use of ETag in S3?

The entity tag is a hash of the object. The ETag reflects changes only to the contents of an object, not its metadata. The ETag may or may not be an MD5 digest of the object data.

How S3 ETag is calculated?

Calculating the S3 ETag for a local file Read the file in chunks of 173015040 bytes. Calculate the MD5 checksum for each chunk and store it for later use. Calculate the md5 hexdigest of the concatenated checksums.

What is ETag in AWS?

AWS: The ETag for an object created using the multipart upload api will contain one or more non-hexadecimal characters and/or will consist of less than 16 or more than 16 hexadecimal digits.


1 Answers

It doesn't really have 2 extra characters. There are two things happening, here.

ETags are required to be wrapped in " quotes, so the ETag of the object is "7bd173e5150f57f8ffe94ad61cd5ea9d" -- the quotes are part of the ETag.

And, this output is JSON, where strings are required to be wrapped in " ... so the " character in a string must be escaped with a backslash -- e.g. the 5-character string "foo" (with the quote characters shown being part of the string itself, as opposed to simply enclosing the string), in JSON, is represented as "\"foo\"".

like image 179
Michael - sqlbot Avatar answered Sep 22 '22 04:09

Michael - sqlbot