Soru

Zorluk: OrtaManage Properties, Metadata, and Access Tiers for Azure Blob Storage

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?

  1. 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
  2. B
    var 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);
  3. C
    var metadata = new Dictionary<string, string> { { "Project", "Delta" } };

    await blobClient.SetMetadataAsync(metadata);
    await blobClient.SetAccessTierAsync(AccessTier.Cool);
  4. D
    var 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

1
Define the metadata dictionary containing the target key-value pairs without manual prefixes.
A dictionary is created containing the key 'Project' with the value 'Delta'.
The Azure Storage SDK handles HTTP header prefixing (x-ms-meta-) automatically, so manual prefixes must be omitted.
2
Instantiate BlobRequestConditions containing the active lease ID.
A request conditions instance is initialized with the LeaseId property set to '5e2b834b-74d1-4e0d-b8d2-5a210d7a04bc'.
Since the blob has an active lease, all write operations require the lease ID to verify write authorization.
3
Invoke SetMetadataAsync and SetAccessTierAsync sequentially, passing the request conditions containing the lease ID to both methods.
The metadata is successfully updated and the access tier is changed on the leased blob without raising concurrency exceptions.
Both methods represent write operations on the blob resource and will fail with a 412 (Precondition Failed) status code if the lease conditions are omitted.

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.
Bu soruyu puanla