Soru

Zorluk: KolayPerform Blob and Container Operations using Azure Storage SDKs

You need to write a C# application using the Azure.Storage.Blobs SDK (v12) to temporarily lock a blob for exclusive write access. Arrange the following steps in the correct order to acquire a 30-second lease, perform operations, and then clean up the lease resource.

  1. 1Instantiate a BlobClient representing the target blob in your storage account container.
  2. 2Call GetBlobLeaseClient on the BlobClient instance to initialize a BlobLeaseClient object.
  3. 3Invoke AcquireAsync on the BlobLeaseClient, specifying a TimeSpan of 30 seconds.
  4. 4Call ReleaseAsync on the BlobLeaseClient to free the lease once operations are finished.

Cevap

First instantiate a BlobClient, then initialize a BlobLeaseClient using GetBlobLeaseClient, next call AcquireAsync to secure the lease, and finally call ReleaseAsync to unlock the blob.
The correct sequence begins with creating the base BlobClient targeting the blob. Next, you must instantiate a BlobLeaseClient by calling the GetBlobLeaseClient extension method on the BlobClient. Once initialized, AcquireAsync is invoked on the lease client to lock the blob. Finally, after performing modifications, ReleaseAsync is called to free the lock.

Adım Adım Çözüm

1
Instantiate the BlobClient.
A BlobClient instance representing the specific blob is obtained.
All blob-level operations require a client targeting the resource.
2
Initialize the BlobLeaseClient.
A BlobLeaseClient bound to the BlobClient is obtained.
Lease operations are handled by the BlobLeaseClient class in Azure.Storage.Blobs (v12).
3
Acquire the lease.
The blob is locked for 30 seconds, returning a lease ID.
The lease must be active before modifying the blob or before releasing it.
4
Release the lease.
The lease is removed and the blob is unlocked.
This unlocks the blob so that other writers are not blocked once the task is completed.

Anahtar Kavram

Acquiring and releasing leases using the Azure.Storage.Blobs SDK (v12) BlobLeaseClient.
Bu soruyu puanla