You are developing a C# application using the Azure.Storage.Blobs SDK (version 12) to update the metadata and change the access tier of an existing block blob. The blob is currently leased under the lease ID 5e2b834b-74d1-4e0d-b8d2-5a210d7a04bc. You must set a custom metadata tag Project to Delta and change the blob's access tier to Cool. Which C# code snippet should you use to successfully perform these operations?
- var metadata = new Dictionary<string, string> { { "Project", "Delta" } };
var conditions = new BlobRequestConditions { LeaseId = "5e2b834b-74d1-4e0d-b8d2-5a210d7a04bc" };
await blobClient.SetMetadataAsync(metadata, conditions);
await blobClient.SetAccessTierAsync(AccessTier.Cool, conditions: conditions);Cevap - Bvar metadata = new Dictionary<string, string> { { "x-ms-meta-Project", "Delta" } };
var conditions = new BlobRequestConditions { LeaseId = "5e2b834b-74d1-4e0d-b8d2-5a210d7a04bc" };
await blobClient.SetMetadataAsync(metadata, conditions);
await blobClient.SetAccessTierAsync(AccessTier.Cool, conditions: conditions); - Cvar metadata = new Dictionary<string, string> { { "Project", "Delta" } };
await blobClient.SetMetadataAsync(metadata);
await blobClient.SetAccessTierAsync(AccessTier.Cool); - Dvar response = await blobClient.GetPropertiesAsync();
response.Value.Metadata.Add("Project", "Delta");
var conditions = new BlobRequestConditions { LeaseId = "5e2b834b-74d1-4e0d-b8d2-5a210d7a04bc" };
await blobClient.SetAccessTierAsync(AccessTier.Cool, conditions: conditions);
Cevap
The correct option sets the custom metadata key without the standard prefix, instantiates the request conditions with the active lease ID, and passes those conditions to both SetMetadataAsync and SetAccessTierAsync.
The correct snippet successfully updates the metadata and changes the access tier because it passes the active lease ID inside the BlobRequestConditions to both asynchronous write calls. It also defines the custom metadata key without the x-ms-meta- prefix, allowing the SDK to handle the header prefixing automatically.
Adım Adım Çözüm
Anahtar Kavram
To modify the metadata or change the access tier of a leased blob, write operations must include the active lease ID via BlobRequestConditions. Custom metadata keys must be defined without the 'x-ms-meta-' header prefix as the SDK applies it automatically.