You are developing a Python application that uses the azure-storage-blob SDK to retrieve properties for an Azure Storage blob. The blob has custom metadata configured with a key of Department and a value of Sales. You retrieve the blob's properties using properties = blob_client.get_blob_properties(). Which of the following code segments should you use to retrieve the metadata value?
- Adepartment = properties.metadata.get('x-ms-meta-Department')
- department = properties.metadata.get('Department')Answer
- Cdepartment = properties.metadata.get('department')
- Ddepartment = properties.metadata.get('x-ms-meta-department')
Answer
The correct line of code is department = properties.metadata.get('Department') because metadata keys are case-sensitive and do not include the x-ms-meta- prefix in the SDK dictionary.
The correct code segment accesses the metadata dictionary using the exact key name without the x-ms-meta- prefix. Since the key was uploaded as 'Department', calling .get('Department') correctly retrieves 'Sales'.
Step-by-Step Solution
Key Concept
Accessing blob metadata keys in the Azure SDK requires using the exact casing without the x-ms-meta- prefix.