Soru

Zorluk: OrtaPerform Blob and Container Operations using Azure Storage SDKs

You are developing a C# service that periodically updates a shared configuration file stored as a block blob in Azure Blob Storage. To prevent concurrent writes, another process has acquired an active lease on the blob, and the lease ID is stored in a string variable named `currentLeaseId`. Which of the following code segments must you use to successfully overwrite the blob with new data while respecting the active lease?

  1. var options = new BlobUploadOptions
    {
    Conditions = new BlobRequestConditions { LeaseId = currentLeaseId }
    };
    await blobClient.UploadAsync(dataStream, options);
    Cevap
  2. B
    var accessCondition = AccessCondition.GenerateLeaseCondition(currentLeaseId);
    await blobClient.UploadAsync(dataStream, accessCondition);
  3. C
    await blobClient.UploadAsync(dataStream, currentLeaseId);
  4. D
    var options = new BlobUploadOptions
    {
    HttpHeaders = new BlobHttpHeaders { LeaseId = currentLeaseId }
    };
    await blobClient.UploadAsync(dataStream, options);

Cevap

Use BlobUploadOptions with its Conditions property set to a new BlobRequestConditions object containing the active LeaseId, and pass it to BlobClient.UploadAsync.
To perform operations on a leased blob, you must provide the active lease ID as part of the request conditions. In the modern Azure.Storage.Blobs SDK (v12) for C#, this is achieved by creating a new `BlobUploadOptions` object, initializing its `Conditions` property with a `BlobRequestConditions` instance, and setting the `LeaseId` property of that instance to the active lease ID. This options object is then passed as the second parameter to `BlobClient.UploadAsync`.

Adım Adım Çözüm

1
Identify the correct options class for configuring upload parameters in the modern Azure.Storage.Blobs SDK.
Determine that `BlobUploadOptions` is used to configure optional settings during a blob upload.
The modern SDK uses structured options objects instead of raw parameters to support cleaner API overloads.
2
Find where request constraints and lease details are stored in the options object.
Locate the `Conditions` property of type `BlobRequestConditions` on the `BlobUploadOptions` class.
Lease IDs and concurrency checks (ETags) are categorized under request conditions.
3
Instantiate the condition object and set the lease identifier.
Set `LeaseId` within `BlobRequestConditions` to the active lease string value.
Providing the lease ID in the request conditions tells Azure Blob Storage that the writer owns the lease.

Anahtar Kavram

Handling active leases when performing write operations on block blobs using the Azure.Storage.Blobs SDK in C#.
Tahmini Süre:1m 30s
Bu soruyu puanla