Question

Difficulty: MediumPerform Blob and Container Operations using Azure Storage SDKs

You are developing a C# console application that uses the Azure.Storage.Blobs SDK (v12). The application retrieves properties for a blob container that has a custom metadata key named `Owner` set to `DevOps`.

You execute the following code to retrieve the container properties:
csharp
var containerClient = new BlobContainerClient(connectionString, "production-logs");
var properties = await containerClient.GetPropertiesAsync();

You need to extract the value of the `Owner` metadata field both directly from the SDK properties dictionary and from the raw HTTP headers.

Which two code segments should you use?

  1. properties.Value.Metadata["Owner"]Answer
  2. B
    properties.Value.Metadata["x-ms-meta-Owner"]
  3. properties.GetRawResponse().Headers.TryGetValue("x-ms-meta-owner", out string value)Answer
  4. D
    properties.GetRawResponse().Headers.TryGetValue("Owner", out string value)

Answer

To retrieve the metadata value using the properties dictionary, access the key directly without the prefix, such as properties.Value.Metadata["Owner"]. To retrieve the metadata from the raw HTTP response headers, search using the full prefix, such as properties.GetRawResponse().Headers.TryGetValue("x-ms-meta-owner", out string value).
When retrieving custom metadata via the C# SDK, the Azure.Storage.Blobs SDK maps HTTP headers starting with x-ms-meta- into the Metadata dictionary and removes the prefix. Therefore, properties.Value.Metadata["Owner"] correctly retrieves the metadata. Conversely, when inspecting raw HTTP response headers directly via the Response object, you bypass this parsing step and must query the exact HTTP header name, which is x-ms-meta-owner.

Step-by-Step Solution

1
Retrieve the container properties asynchronously from the Azure Blob Storage service.
You obtain a Response<BlobContainerProperties> object containing the properties and the raw HTTP response headers.
Before inspecting metadata, you must execute a call to the storage service to get the latest metadata attributes.
2
Query the custom metadata via the SDK dictionary.
The SDK strips the x-ms-meta- prefix from the HTTP headers, mapping the keys directly. You retrieve the value using the key "Owner".
The SDK provides a parsed, user-friendly Metadata dictionary where the HTTP header prefix is omitted.
3
Query the custom metadata via the raw HTTP response headers.
The raw headers contain the key prefixed as x-ms-meta-owner. You lookup this header using TryGetValue.
Accessing raw headers bypasses SDK stripping, requiring the full HTTP header representation as returned by the REST API.

Key Concept

Understanding how the Azure Blob Storage SDK exposes custom metadata keys vs. how they are represented in raw HTTP response headers.
Rate this question