Soru

Zorluk: OrtaPerform Blob and Container Operations using Azure Storage SDKs

A company implements a data ingestion system using C# and the Azure.Storage.Blobs SDK (v12). A background service must overwrite the content of an existing block blob. To prevent concurrent write conflicts, an active lease has already been acquired on the target blob. The active lease ID is stored in a string variable named `activeLeaseId`.

You need to write the code that uploads the new content to the block blob, ensuring that the operation fails if the lease ID does not match. Which code segment should you use to perform the upload?

  1. A
    var options = new BlobUploadOptions
    {
    AccessConditions = new BlobAccessConditions { LeaseId = activeLeaseId }
    };
    await blobClient.UploadAsync(contentStream, options);
  2. B
    var options = new BlobUploadOptions
    {
    LeaseId = activeLeaseId
    };
    await blobClient.UploadAsync(contentStream, options);
  3. var options = new BlobUploadOptions
    {
    Conditions = new BlobRequestConditions { LeaseId = activeLeaseId }
    };
    await blobClient.UploadAsync(contentStream, options);
    Cevap
  4. D
    var options = new BlobUploadOptions
    {
    Conditions = new BlobRequestConditions { Lease = activeLeaseId }
    };
    await blobClient.UploadAsync(contentStream, options);

Cevap

Use BlobUploadOptions with the Conditions property set to a new instance of BlobRequestConditions with LeaseId set to activeLeaseId.
The correct answer correctly instantiates a BlobUploadOptions object, sets its Conditions property to a new instance of BlobRequestConditions, and assigns the lease ID to the LeaseId property. In Azure.Storage.Blobs v12, this is the standard and correct way to enforce lease constraints on a blob upload operation.

Adım Adım Çözüm

1
Identify the modern Azure.Storage.Blobs SDK (v12) request conditions wrapper.
The BlobRequestConditions class is used to specify conditional access constraints such as lease IDs for blob operations.
This class replaces older access condition models from legacy SDKs.
2
Associate the request conditions with the upload operation.
The BlobUploadOptions class contains a Conditions property of type BlobRequestConditions.
This links the lease constraints to the specific upload request.
3
Set the lease ID condition to target the active lease.
Set the LeaseId property of the BlobRequestConditions instance to activeLeaseId.
This ensures the Azure Storage service validates that the client holds the active lease before completing the write operation.

Anahtar Kavram

Applying lease conditions to Azure Blob Storage write operations using the Azure.Storage.Blobs SDK (v12)
Tahmini Süre:1m 30s
Bu soruyu puanla