Azure / azure-storage-python

Microsoft Azure Storage Library for Python
https://azure-storage.readthedocs.io
MIT License
338 stars 240 forks source link

get md5 for blob #693

Open cometta opened 3 years ago

cometta commented 3 years ago

Is there any azure api call that i can use to retrieve md5 hash for the blob inside a container?

ljluestc commented 10 months ago
from azure.storage.blob import BlobServiceClient

# Your connection string
connection_string = "your_connection_string"

# Your blob container name and blob name
container_name = "your_container_name"
blob_name = "your_blob_name"

# Initialize a BlobServiceClient
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

# Get a reference to the blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)

# Get the properties of the blob
blob_properties = blob_client.get_blob_properties()

# Retrieve the MD5 hash value from the properties
md5_hash = blob_properties.content_settings.content_md5

print(f"MD5 Hash of the blob: {md5_hash}")