Question

Difficulty: MediumPerform Blob and Container Operations using Azure Storage SDKs

You are developing a C# backend application that uses the Azure.Storage.Blobs SDK (v12) to manage resources in Azure Blob Storage. A blob contains custom metadata with a key named `ProjectOwner`.

You retrieve the properties of the blob using the following code:
csharp
BlobProperties properties = (await blobClient.GetPropertiesAsync()).Value;

Which code segment should you use to retrieve the value of the `ProjectOwner` custom metadata key?

  1. A
    string owner = properties.Metadata["x-ms-meta-ProjectOwner"];
  2. B
    string owner = properties.Metadata["x-ms-meta-projectowner"];
  3. string owner = properties.Metadata["ProjectOwner"];Answer
  4. D
    string owner = properties.Metadata["X-Ms-Meta-ProjectOwner"];

Answer

The correct code segment is: string owner = properties.Metadata["ProjectOwner"];
The correct answer correctly queries the dictionary using the key name without the 'x-ms-meta-' prefix. In the Azure.Storage.Blobs SDK, the HTTP response headers are parsed, and the metadata keys are mapped directly into a dictionary with the prefix removed.

Step-by-Step Solution

1
Retrieve the properties of the blob from Azure Storage.
A Response containing the BlobProperties object is returned from the GetPropertiesAsync call.
Before metadata can be accessed, we must query the blob properties from the service.
2
Access the Metadata dictionary.
The Metadata IDictionary is accessed from the BlobProperties instance.
User-defined metadata is stored inside the Metadata property of BlobProperties.
3
Retrieve the value using the key name without the HTTP header prefix.
The value of the 'ProjectOwner' metadata key is successfully retrieved.
The SDK strips 'x-ms-meta-' prefixes from HTTP response headers before populating the dictionary.

Key Concept

Retrieval of custom blob metadata via the C# SDK without HTTP header prefixes
Estimated Time:1m 0s
Rate this question