1

I've just uploaded a 5GB of data and would like to verify that the MD5 sums match. I've calculated this for my local copy of the files, but am having problems fetching ContentMD5 from Azure. So far, I get an empty dict, but I can see the blob names. I've limited it to the first 10 items at the moment, just for debugging. I'm aware that MD5 is different on Azure from a typical md5sum call and have allowed for that locally. But, currently, I cannot see any blob properties. The properties are there when I browse via the Azure console (as is the ContentMD5 property).

Where am I going wrong?

Here's my code at the moment:

import os
from os import sys
from azure.storage.blob import BlobServiceClient

def remote_check(connection_str):
    blob_service_client = BlobServiceClient.from_connection_string(connection_str)
    container_name = "global"
    container = blob_service_client.get_container_client(container=container_name)
    blob_list = container.list_blobs()
    count = 0
    for blob in blob_list:
        if count < 10:
            blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob)
            a = blob_client.get_blob_properties()
            print(a.metadata)
            print("Blob name: " + str(blob_client.blob_name))
            count = count + 1
        else:
           break

def main():
    try:
        CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING']
        remote_check(CONNECTION_STRING)
    except KeyError:
        print("AZURE_STORAGE_CONNECTION_STRING must be set.")
        sys.exit(1)

if __name__ == '__main__':
    main()

2 Answers 2

1

Please make sure you're using the latest version of package azure-storage-blob 12.6.0.

Some properties are in the content_settings, for example, to get content_md5, you should use the following code:

a=blob_client.get_blob_properties()
print(a.content_settings.content_md5)

Here is the my test result:

enter image description here

Sign up to request clarification or add additional context in comments.

7 Comments

I can confirm this works. Is this a bug with azure, or just plain trickery? ;-) Thanks for the reply
@Adam, it's not a bug. It should be the changes in these new packages. And if it's helpful, please accept it as answer:).
Many thanks @Ivan-Yang. Answer accepted. If it's not a bug, then perhaps the documentation is out of date?
@Adam, can you provide the link to me?
@Adam, the doc is correct, but some properties still need to be extracted again. When you look at the doc get_blob_properties, it actually returns BlobProperties, and you can find that it has content_settings.
|
0

Maybe you can check the blob properties with a rest (e.g. with an rest client like postman) call described here:

https://learn.microsoft.com/en-us/rest/api/storageservices/get-blob-properties

The "Content-MD5" is returned as HTTP-Response Header.

1 Comment

I'm not the Azure admin and don't have privileges to access the command az ad sp create-for-rbac -n "myaccount"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.