Question

Difficulty: EasyPerform Blob and Container Operations using Azure Storage SDKs

An application needs to assign custom metadata to an Azure Blob Storage container. You write C# code using the Azure.Storage.Blobs SDK (v12) to define the metadata. You want to store a custom key named Environment with the value Production.

Which of the following code snippets correctly defines the metadata dictionary?

  1. A
    var metadata = new Dictionary<string, string>
    {
    { "x-ms-meta-Environment", "Production" }
    };
  2. var metadata = new Dictionary<string, string>
    {
    { "Environment", "Production" }
    };
    Answer
  3. C
    var metadata = new Dictionary<string, string>
    {
    { "x-ms-meta-environment", "Production" }
    };
  4. D
    var metadata = new Dictionary<string, string>
    {
    { "metadata-Environment", "Production" }
    };

Answer

The correct option is the dictionary that defines 'Environment' as the key directly, without any prefixes, like: new Dictionary<string, string> { { "Environment", "Production" } }.
When using the Azure.Storage.Blobs SDK (v12) in C#, metadata is defined as a standard Dictionary<string, string>. The SDK automatically handles prepending the 'x-ms-meta-' prefix to each key when making the REST API call to Azure Storage. Therefore, you only need to specify the custom key name, such as 'Environment', directly in the dictionary.

Step-by-Step Solution

1
Identify the target metadata key and value.
The target key is 'Environment' and the value is 'Production'.
This matches the requirements of the custom metadata to be stored.
2
Determine if any prefixes are required when using the C# Azure.Storage.Blobs SDK (v12).
No prefix (such as 'x-ms-meta-') should be prepended manually to the dictionary key.
The SDK automatically adds the 'x-ms-meta-' prefix to the dictionary keys before transmitting the HTTP request headers.
3
Construct the Dictionary<string, string> with the clean key and value.
The dictionary should have the key 'Environment' and value 'Production'.
This matches the correct dictionary definition for setting metadata in the Azure SDK.

Key Concept

Azure Storage Blob Metadata SDK Configuration
Estimated Time:45s
Rate this question