Question

Difficulty: MediumPerform Blob and Container Operations using Azure Storage SDKs

You are developing a Python application that uses the `azure-storage-blob` (v12) SDK. The application must retrieve custom metadata from a blob named `financial_summary.xlsx` in a container named `archive`. The blob was previously uploaded with a custom metadata key-value pair of `Department: Finance`.

You write the following code:
python
from azure.storage.blob import BlobServiceClient

connection_string = "your_connection_string"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container="archive", blob="financial_summary.xlsx")

# Retrieve properties
properties = blob_client.get_blob_properties()

Which two of the following Python expressions will successfully retrieve the value of the department metadata ("Finance") from the `properties` object? (Choose two.)

  1. `properties.metadata.get('department')`Answer
  2. `properties.metadata['department']`Answer
  3. C
    `properties.metadata.get('Department')`
  4. D
    `properties.metadata.get('x-ms-meta-department')`

Answer

The correct expressions are the ones accessing the metadata dictionary using lowercase keys without the 'x-ms-meta-' prefix, specifically by using the get method with 'department' or by indexing directly with 'department'.
When retrieving blob properties, the Azure Storage SDK parses the HTTP response headers. It removes the 'x-ms-meta-' prefix and converts the header names to lowercase before storing them in the metadata dictionary. Therefore, the metadata dictionary contains the key 'department' in lowercase, and can be successfully accessed using direct indexing or the get method with the lowercase key.

Step-by-Step Solution

1
Understand how the Azure Storage SDK handles HTTP headers for custom metadata.
Custom metadata is sent over HTTP with the 'x-ms-meta-' prefix (e.g., 'x-ms-meta-Department: Finance').
This is the protocol-level behavior of Azure Blob Storage.
2
Determine how the Python SDK parses and exposes these metadata headers.
The SDK strips the 'x-ms-meta-' prefix and normalizes all keys to lowercase, storing them in a standard Python dictionary under the 'metadata' property.
This simplifies key access for developers and abstracts HTTP header naming conventions.
3
Identify the correct way to query the dictionary in Python.
Access the key using the lowercase string 'department' either via dictionary indexing or the '.get()' method.
Case-sensitive lookups for the original casing or lookups including the prefix will not match the processed keys in the dictionary.

Key Concept

Azure Blob Storage SDK metadata casing normalization and prefix stripping
Estimated Time:1m 30s
Rate this question