All Products
Search
Document Center

Object Storage Service:Checking OSS MD5 consistency

Last Updated:Mar 20, 2026

No. ETag values in Object Storage Service (OSS) identify whether the content of an object has changed — they are not always equal to the MD5 hash of the object. Do not use ETag values to verify data integrity.

Verify upload integrity with Content-MD5

To confirm that an uploaded object matches your local file, include the Content-MD5 header in the upload request. OSS computes the MD5 hash of the received object and compares it with the Content-MD5 value you provided. The upload succeeds only if the two values match. Including this header is optional, but it lets you verify data integrity as part of the upload process.

Note

The Content-MD5 header must be included in the signature calculation. If the header value does not match the signature, OSS returns a SignatureDoesNotMatch error. For details, see Include signatures in the Authorization header.

Calculate the Content-MD5 value

The Content-MD5 value is the Base64-encoded binary MD5 digest of the request body — not the Base64 encoding of the hexadecimal string.

The following examples use the string 0123456789 to illustrate the correct and incorrect approaches.

Correct calculation

  1. Compute the MD5 hash of the data to get a 128-bit binary digest.

  2. Base64-encode the binary digest.

>>> import base64, hashlib
>>> hash = hashlib.md5()
>>> hash.update("0123456789")   # Python 3: hash.update(b"0123456789")
>>> base64.b64encode(hash.digest())
'eB5eJF1ptWaXm4bijSPyxw=='

hash.digest() returns the 128-bit binary digest:

>>> hash.digest()
'x\x1e^$]i\xb5f\x97\x9b\x86\xe2\x8d#\xf2\xc7'

Incorrect calculation

A common mistake is to Base64-encode the 32-character hexadecimal string instead of the binary digest. This produces an incorrect Content-MD5 value.

# hash.hexdigest() returns a 32-character hexadecimal string — do not use this for Content-MD5.
>>> hash.hexdigest()
'781e5e245d69b566979b86e28d23f2c7'
# Base64-encoding the hex string produces the wrong result:
>>> base64.b64encode(hash.hexdigest())
'NzgxZTVlMjQ1ZDY5YjU2Njk3OWI4NmUyOGQyM2YyYzc='