You are developing a C# console application using the Azure.Storage.Blobs SDK (v12). The application needs to update a blob named report.pdf. To prevent other processes from modifying the blob during the update, you must acquire a 30-second lease on the blob, upload the new content from a stream named contentStream, and then release the lease.
Which two code segments should you use to perform these operations? (Select two.)
- BlobLeaseClient leaseClient = blobClient.GetBlobLeaseClient();
var response = await leaseClient.AcquireAsync(TimeSpan.FromSeconds(30));
string leaseId = response.Value.LeaseId;Cevap - var options = new BlobUploadOptions
{
Conditions = new BlobRequestConditions { LeaseId = leaseId }
};
await blobClient.UploadAsync(contentStream, options);Cevap - CBlobLeaseClient leaseClient = blobClient.GetBlobLeaseClient();
var response = await leaseClient.AcquireAsync(TimeSpan.FromSeconds(5));
string leaseId = response.Value.LeaseId; - Dvar options = new BlobUploadOptions
{
HttpHeaders = new BlobHttpHeaders { CacheControl = leaseId }
};
await blobClient.UploadAsync(contentStream, options);
Cevap
To perform a lease-protected update on a blob, you must first obtain a BlobLeaseClient and call AcquireAsync with a duration between 15 and 60 seconds (such as 30 seconds), then pass the acquired LeaseId in the request Conditions property of the BlobUploadOptions when calling UploadAsync.
To safely modify a leased blob, you must acquire a lease and supply the acquired lease ID in the write request. The step of calling AcquireAsync with a duration of 30 seconds correctly obtains the lease because the duration lies within the required range of 15 to 60 seconds. The step of initializing BlobUploadOptions with BlobRequestConditions containing the LeaseId correctly authorizes the write operation during the upload call.
Adım Adım Çözüm
Anahtar Kavram
Performing Blob lease operations and using lease request conditions to write to leased blobs.