Soru

Zorluk: OrtaPerform Blob and Container Operations using Azure Storage SDKs

A developer uploads a blob to Azure Blob Storage and configures its metadata using the Azure.Storage.Blobs SDK (v12) for C# with the following code:

csharp
var metadata = new Dictionary<string, string>
{
{ "Department", "Finance" }
};
await blobClient.SetMetadataAsync(metadata);

Later, the developer retrieves the properties of the blob using the following code:

csharp
BlobProperties properties = await blobClient.GetPropertiesAsync();

Which code segment should the developer use to successfully retrieve the metadata value "Finance"?

  1. A
    string department = properties.Metadata["Department"];
  2. string department = properties.Metadata["department"];Cevap
  3. C
    string department = properties.Metadata["x-ms-meta-department"];
  4. D
    string department = properties.Metadata["x-ms-meta-Department"];

Cevap

string department = properties.Metadata["department"];
The correct answer uses the lowercase key 'department'. The Azure Storage REST API returns custom metadata as HTTP headers with the 'x-ms-meta-' prefix, converting key names to lowercase. The Azure.Storage.Blobs SDK automatically strips the 'x-ms-meta-' prefix but leaves the keys lowercased. Since the standard .NET Dictionary used for properties.Metadata is case-sensitive, the lookup must match the lowercase format exactly.

Adım Adım Çözüm

1
Analyze how custom metadata headers are processed by the Azure Storage service.
The service stores custom metadata as HTTP headers, prepending each key with 'x-ms-meta-' and converting all characters to lowercase.
Understanding the service-side serialization explains the format of the keys returned during retrieval.
2
Analyze how the Azure.Storage.Blobs SDK processes retrieved metadata.
The SDK strips the 'x-ms-meta-' prefix from HTTP headers but preserves the lowercase format returned by the service when constructing the Metadata dictionary.
This determines that the final keys in the dictionary will be in lowercase.
3
Perform dictionary retrieval using the correct key format.
Accessing properties.Metadata["department"] returns the correct value because dictionary key lookup in .NET is case-sensitive, matching the lowercase key.
Selecting the exact key prevents a KeyNotFoundException.

Anahtar Kavram

Azure Blob Storage SDK metadata naming casing rules and prefix stripping
Bu soruyu puanla