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?
- Avar options = new BlobUploadOptions
{
AccessConditions = new BlobAccessConditions { LeaseId = activeLeaseId }
};
await blobClient.UploadAsync(contentStream, options); - Bvar options = new BlobUploadOptions
{
LeaseId = activeLeaseId
};
await blobClient.UploadAsync(contentStream, options); - var options = new BlobUploadOptions
{
Conditions = new BlobRequestConditions { LeaseId = activeLeaseId }
};
await blobClient.UploadAsync(contentStream, options);Cevap - Dvar 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
Anahtar Kavram
Applying lease conditions to Azure Blob Storage write operations using the Azure.Storage.Blobs SDK (v12)
Tahmini Süre:1m 30s