You are developing a Python application that uses the `azure-storage-blob` SDK (v12). You write the following code to upload a blob and assign custom metadata:
python
from azure.storage.blob import BlobServiceClient
service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = service_client.get_blob_client(container="reports", blob="annual_report.pdf")
blob_client.upload_blob(data=pdf_data, metadata={"ProjectName": "Delta"}, overwrite=True)
Later, you need to read this metadata value from the blob. Which code segment should you use to retrieve the value of the `ProjectName` metadata?
- Apython
properties = blob_client.get_blob_properties()
project_name = properties.metadata.get("ProjectName") - Bpython
properties = blob_client.get_blob_properties()
project_name = properties.metadata.get("x-ms-meta-projectname") - python
properties = blob_client.get_blob_properties()
project_name = properties.metadata.get("projectname")
Cevap - Dpython
properties = blob_client.get_blob_properties()
project_name = properties.metadata.get("x-ms-meta-ProjectName")
Cevap
Retrieve the blob properties and access the metadata dictionary using the lowercase key 'projectname' without any 'x-ms-meta-' prefix.
The correct option retrieves the metadata using the key in lowercase ('projectname'). This is because the Azure Storage SDK for Python normalizes all metadata keys to lowercase and strips the 'x-ms-meta-' prefix.
Adım Adım Çözüm
Anahtar Kavram
Azure Blob metadata keys are case-insensitive HTTP headers under the hood; the Python SDK handles this by stripping the 'x-ms-meta-' prefix and exposing all keys in lowercase.