Question

Difficulty: MediumPerform Blob and Container Operations using Azure Storage SDKs

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?

  1. A
    var metadata = new Dictionary<string, string>
    {
    { "ProcessedBy", "SyncService" }
    };
    await blobClient.SetMetadataAsync(metadata);
  2. var metadata = new Dictionary<string, string>
    {
    { "ProcessedBy", "SyncService" }
    };
    var conditions = new BlobRequestConditions { LeaseId = activeLeaseId };
    await blobClient.SetMetadataAsync(metadata, conditions);
    Answer
  3. C
    var metadata = new Dictionary<string, string>
    {
    { "x-ms-meta-ProcessedBy", "SyncService" }
    };
    var conditions = new BlobRequestConditions { LeaseId = activeLeaseId };
    await blobClient.SetMetadataAsync(metadata, conditions);
  4. D
    var 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

1
Identify the active concurrency control on the blob.
The blob is currently leased by an external process, meaning all write and delete operations require the associated lease ID.
Azure Storage requires the lease ID in request headers/options to allow modifying a leased resource.
2
Construct the metadata dictionary payload.
Define the metadata dictionary with the key 'ProcessedBy' and value 'SyncService'.
In the modern Azure.Storage.Blobs SDK (v12), custom metadata keys are passed without the 'x-ms-meta-' HTTP header prefix because the SDK automatically adds it during transmission.
3
Call the appropriate SDK method passing request conditions.
Initialize 'BlobRequestConditions' with the 'LeaseId' property set, and call 'SetMetadataAsync'.
This sends the metadata update payload along with the lease credentials to authorize the change without breaking the lease.

Key Concept

Handling metadata updates on leased blobs using modern Azure Storage SDK (v12) request conditions.
Rate this question