Soru

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

You are developing a C# service that updates the metadata of a blob in Azure Blob Storage using the Azure.Storage.Blobs SDK. The target blob is currently locked with an active lease. You have the lease ID stored in a variable named `activeLeaseId` and the metadata dictionary stored in a variable named `metadata`.

Which of the following code segments should you use to successfully update the blob's metadata?

  1. await blobClient.SetMetadataAsync(metadata, new BlobRequestConditions { LeaseId = activeLeaseId });Cevap
  2. B
    await blobClient.SetMetadataAsync(metadata);
  3. C
    await blobClient.SetMetadataAsync(metadata, activeLeaseId);
  4. D
    await blobClient.SetMetadataAsync(metadata, new RequestConditions { IfMatch = new ETag(activeLeaseId) });

Cevap

The correct option is the one that calls the SetMetadataAsync method with a BlobRequestConditions object containing the LeaseId property set to the active lease ID.
The correct code block initializes a BlobRequestConditions object and sets its LeaseId property to the activeLeaseId. This object is then passed as the second argument to SetMetadataAsync, which correctly informs Azure Blob Storage of the authorized lease hold for the write operation.

Adım Adım Çözüm

1
Identify the requirement to update a leased blob's metadata.
Any write or update operation on a leased blob requires the active lease ID to be passed as part of the request conditions.
Azure Blob Storage enforces leases to prevent concurrent write conflicts, and requests without the lease ID on a leased resource fail with an HTTP 412 error.
2
Select the correct SDK class for passing request conditions in the Azure.Storage.Blobs SDK.
The BlobRequestConditions class should be instantiated, and its LeaseId property must be set to the active lease ID.
The base RequestConditions class does not expose the LeaseId property, which is specific to blob storage operations.
3
Call the SetMetadataAsync method with the metadata dictionary and the request conditions.
await blobClient.SetMetadataAsync(metadata, new BlobRequestConditions { LeaseId = activeLeaseId });
This matches the signature of the SDK's SetMetadataAsync overload that accepts request conditions.

Anahtar Kavram

To modify a leased blob or its metadata, you must provide the active lease ID using the BlobRequestConditions class in the Azure.Storage.Blobs SDK.
Tahmini Süre:1m 30s
Bu soruyu puanla