Question

Difficulty: EasyPerform Blob and Container Operations using Azure Storage SDKs

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?

  1. A
    department = properties.metadata.get('x-ms-meta-Department')
  2. department = properties.metadata.get('Department')Answer
  3. C
    department = properties.metadata.get('department')
  4. D
    department = 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

1
Retrieve blob properties from Azure Storage.
A BlobProperties object is returned containing a metadata dictionary.
To inspect user-defined custom metadata, the application must first call get_blob_properties() to load the metadata into memory.
2
Access the metadata dictionary using the exact case-sensitive key.
The metadata value is extracted using the key 'Department'.
The azure-storage-blob SDK strips the x-ms-meta- HTTP header prefix when exposing metadata in the Python dictionary, but preserves the casing configured during upload.

Key Concept

Accessing blob metadata keys in the Azure SDK requires using the exact casing without the x-ms-meta- prefix.
Rate this question