An enterprise data archive application written in C# needs to update the custom metadata of an existing blob named `log-archive.txt` inside a container named `logs` using the `Azure.Storage.Blobs` SDK (v12). The blob currently has an active lease held by another process with the ID stored in a string variable named `activeLeaseId`.
You need to write the code to update the metadata dictionary with a key of `ProcessedBy` and a value of `SyncService`. The update must succeed without breaking or releasing the lease.
Which code segment should you use?
- Avar metadata = new Dictionary<string, string>
{
{ "ProcessedBy", "SyncService" }
};
await blobClient.SetMetadataAsync(metadata); - var metadata = new Dictionary<string, string>
{
{ "ProcessedBy", "SyncService" }
};
var conditions = new BlobRequestConditions { LeaseId = activeLeaseId };
await blobClient.SetMetadataAsync(metadata, conditions);Answer - Cvar metadata = new Dictionary<string, string>
{
{ "x-ms-meta-ProcessedBy", "SyncService" }
};
var conditions = new BlobRequestConditions { LeaseId = activeLeaseId };
await blobClient.SetMetadataAsync(metadata, conditions); - Dvar metadata = new Dictionary<string, string>
{
{ "ProcessedBy", "SyncService" }
};
var sasUri = blobClient.GenerateSasUri(BlobSasPermissions.Read | BlobSasPermissions.Write | BlobSasPermissions.Delete, DateTimeOffset.UtcNow.AddDays(30));
var sasClient = new BlobClient(sasUri);
await sasClient.SetMetadataAsync(metadata);
Answer
The correct option initializes the metadata dictionary using the key 'ProcessedBy' and values 'SyncService', instantiates a 'BlobRequestConditions' object containing the 'LeaseId' set to 'activeLeaseId', and passes both objects to 'SetMetadataAsync'.
The correct option correctly configures a 'BlobRequestConditions' object with the lease ID. Because the target blob has an active lease, passing the lease ID is required to authorize the metadata write. Additionally, it defines the metadata key using the key 'ProcessedBy' without the REST API prefix. The SDK manages prefixing automatically, so omitting it ensures that the metadata key is correctly resolved.
Step-by-Step Solution
Key Concept
Handling metadata updates on leased blobs using modern Azure Storage SDK (v12) request conditions.