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?
- Ametadata.Add("x-ms-meta-Department", "Marketing");
- metadata.Add("Department", "Marketing");Answer
- Cmetadata.Add("x-ms-meta-department", "Marketing");
- Dmetadata.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
Key Concept
Azure Blob Metadata SDK Operations