Question

Difficulty: EasyPerform Blob and Container Operations using Azure Storage SDKs

You are developing a C# application that uses the Azure.Storage.Blobs SDK (v12) to manage blobs. You need to assign custom metadata to an existing blob to track the department that owns the blob. The metadata key must be 'Department' and the value must be 'Marketing'.

You write the following code:
csharp
BlobClient blobClient = new BlobClient(connectionString, containerName, blobName);
IDictionary<string, string> metadata = new Dictionary<string, string>();
// Code to add the metadata pair
await blobClient.SetMetadataAsync(metadata);

Which code segment should you use to add the metadata key-value pair?

  1. A
    metadata.Add("x-ms-meta-Department", "Marketing");
  2. metadata.Add("Department", "Marketing");Answer
  3. C
    metadata.Add("x-ms-meta-department", "Marketing");
  4. D
    metadata.Add("X-Ms-Meta-Department", "Marketing");

Answer

Add the key-value pair using the key 'Department' directly without the HTTP prefix, as in: metadata.Add("Department", "Marketing");
The correct option correctly uses the dictionary key 'Department' without the HTTP header prefix 'x-ms-meta-'. The Azure Storage SDK automatically prepends the required prefix to the custom metadata keys before sending the request to the Azure Storage API.

Step-by-Step Solution

1
Identify the SDK method requirements for setting metadata.
The SetMetadataAsync method accepts an IDictionary<string, string> containing user-defined metadata.
To understand what format the SDK expects for dictionary keys.
2
Determine whether the HTTP prefix is required in the SDK dictionary keys.
The Azure Storage SDK (v12) automatically prepends 'x-ms-meta-' to all dictionary keys when constructing the HTTP request.
To avoid duplicating the prefix and causing malformed headers.
3
Select the code segment that defines the key directly.
Using 'Department' directly matches the correct implementation.
This ensures that the final HTTP header sent is 'x-ms-meta-Department' with the value 'Marketing'.

Key Concept

Azure Blob Metadata SDK Operations
Rate this question