An enterprise application requires copying a blob named `archive.zip` from a source storage account to a destination storage account. The destination blob already exists and is locked with an active, exclusive-write lease. The application must perform the copy operation asynchronously and overwrite the destination blob without breaking or releasing the existing lease. You have retrieved the destination blob's lease ID: `d3b07384-d113-4c4e-a51a-7b2c0f209176`.
Which C# code snippet should you run to perform the copy operation?
- Avar options = new BlobCopyFromUriOptions
{
SourceConditions = new BlobRequestConditions
{
LeaseId = "d3b07384-d113-4c4e-a51a-7b2c0f209176"
}
};
await destBlobClient.StartCopyFromUriAsync(sourceUri, options); - var options = new BlobCopyFromUriOptions
{
DestinationConditions = new BlobRequestConditions
{
LeaseId = "d3b07384-d113-4c4e-a51a-7b2c0f209176"
}
};
await destBlobClient.StartCopyFromUriAsync(sourceUri, options);Answer - Cvar leaseClient = new BlobLeaseClient(destBlobClient, "d3b07384-d113-4c4e-a51a-7b2c0f209176");
await leaseClient.StartCopyFromUriAsync(sourceUri); - Dvar sourceSasUri = sourceBlobClient.GenerateSasUri(BlobSasPermissions.Read | BlobSasPermissions.Write, DateTimeOffset.UtcNow.AddHours(1));
await destBlobClient.StartCopyFromUriAsync(sourceSasUri);
Answer
Use BlobCopyFromUriOptions with DestinationConditions containing the lease ID, and pass it to StartCopyFromUriAsync.
To copy a blob to a destination that has an active exclusive-write lease, you must pass the lease ID associated with the destination blob. In the Azure.Storage.Blobs SDK (v12), this is accomplished by setting the LeaseId property of the BlobRequestConditions assigned to the DestinationConditions of the BlobCopyFromUriOptions object. The destination client uses these conditions to authorize the write operation against the leased blob.
Step-by-Step Solution
Key Concept
Copying blobs to a leased destination using Azure.Storage.Blobs SDK