Soru

Zorluk: ZorMove and Copy Blobs between Azure Storage Containers and Accounts

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?

  1. A
    var options = new BlobCopyFromUriOptions
    {
    SourceConditions = new BlobRequestConditions
    {
    LeaseId = "d3b07384-d113-4c4e-a51a-7b2c0f209176"
    }
    };
    await destBlobClient.StartCopyFromUriAsync(sourceUri, options);
  2. var options = new BlobCopyFromUriOptions
    {
    DestinationConditions = new BlobRequestConditions
    {
    LeaseId = "d3b07384-d113-4c4e-a51a-7b2c0f209176"
    }
    };
    await destBlobClient.StartCopyFromUriAsync(sourceUri, options);
    Cevap
  3. C
    var leaseClient = new BlobLeaseClient(destBlobClient, "d3b07384-d113-4c4e-a51a-7b2c0f209176");
    await leaseClient.StartCopyFromUriAsync(sourceUri);
  4. D
    var sourceSasUri = sourceBlobClient.GenerateSasUri(BlobSasPermissions.Read | BlobSasPermissions.Write, DateTimeOffset.UtcNow.AddHours(1));
    await destBlobClient.StartCopyFromUriAsync(sourceSasUri);

Cevap

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.

Adım Adım Çözüm

1
Identify the source of the lease constraint.
The destination blob is leased, meaning any write operations (like copying over it) require the lease ID.
Applying write operations to a leased blob without the lease ID results in a precondition failure.
2
Configure the BlobCopyFromUriOptions object.
Assign a new BlobRequestConditions object to DestinationConditions, specifying the destination lease ID.
DestinationConditions defines the conditions under which the destination blob can be modified.
3
Execute the copy operation.
Invoke StartCopyFromUriAsync on the destination client, passing the source URI and the configured options.
This starts the asynchronous copy process on the Azure Storage service backend with the correct authorization.

Anahtar Kavram

Copying blobs to a leased destination using Azure.Storage.Blobs SDK
Bu soruyu puanla