Question

Difficulty: HardMove and Copy Blobs between Azure Storage Containers and Accounts

You are writing a C# console application using the Azure.Storage.Blobs SDK (version 12.x) to migrate archive data from a source Azure Storage account to a destination storage account. The source container is private, and you want to perform the transfer asynchronously while monitoring the process. Arrange the following steps in the correct sequence to copy the blob and determine when the operation finishes.

  1. 1Generate a Shared Access Signature (SAS) token with read (r) permission for the source blob.
  2. 2Instantiate a BlobContainerClient representing the destination container.
  3. 3Call GetBlobClient on the destination container client to obtain a BlobClient for the target blob.
  4. 4Call StartCopyFromUriAsync on the destination BlobClient, passing the source blob's URI with the appended SAS token.
  5. 5Call GetPropertiesAsync on the destination BlobClient in a loop and check the CopyStatus property until it is no longer Pending.

Answer

Generate the read-only SAS token for the source blob, instantiate the destination BlobContainerClient, obtain the destination BlobClient, initiate the copy using StartCopyFromUriAsync with the source URI, and poll the destination properties until the CopyStatus completes.
To copy a private blob asynchronously between storage accounts, you must first generate a read-only SAS token for the source blob. Next, create a container client and then a blob client for the destination target. With these clients set up, call StartCopyFromUriAsync on the destination blob client to prompt the service to pull data from the source URI. Finally, poll the destination properties using GetPropertiesAsync to monitor the copy status until it resolves.

Step-by-Step Solution

1
Generate a SAS token with read permissions on the source blob.
An authenticated URI pointing to the source blob is acquired.
The destination storage account requires read authorization to fetch the source blob's data.
2
Instantiate a BlobContainerClient for the destination container.
A service client targeting the destination container is created.
You must have a reference to the container before you can address specific blobs inside it.
3
Call GetBlobClient on the container client.
A BlobClient object representing the destination blob is returned.
The copying action is initiated on the target blob client itself.
4
Invoke StartCopyFromUriAsync on the destination BlobClient.
The copy task is queued on the Azure service backend.
This starts the asynchronous copy operation between the storage accounts.
5
Loop to call GetPropertiesAsync on the destination BlobClient.
The copy process completes with success or failure.
Because the copy is executed on the Azure service backend, the client must query the destination blob properties to find out when the status changes from Pending.

Key Concept

Asynchronous Blob Copying using the Azure.Storage.Blobs SDK

Alternative Method

Instead of polling the destination blob properties programmatically, you can listen to Microsoft.Storage.BlobCreated events using Azure Event Grid to handle completion reactively.
Estimated Time:2m 0s
Rate this question