Question

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

A developer is writing a service in C# that moves large backup files from a public container to a secure archival container in a different Azure Storage account using the Azure.Storage.Blobs SDK (version 12.x). The operation must execute asynchronously and log a message once the file transfer completes successfully. Place the steps in the correct order to programmatically copy the blob and monitor the progress of the copy operation.

  1. 1Instantiate a BlobContainerClient targeting the destination storage account container.
  2. 2Call GetBlobClient on the container client to retrieve a reference to the destination BlobClient.
  3. 3Invoke StartCopyFromUriAsync on the destination BlobClient, passing the source blob's SAS URI.
  4. 4Invoke GetPropertiesAsync on the destination BlobClient to retrieve the current operation state.
  5. 5Check if CopyStatus is Pending and loop, waiting before fetching properties again until it changes.

Answer

To perform an asynchronous copy operation and monitor it using the Azure.Storage.Blobs SDK, first instantiate the BlobContainerClient for the destination container. Second, retrieve the target BlobClient from that container. Third, call StartCopyFromUriAsync on the destination client with the source SAS URI. Fourth, call GetPropertiesAsync to fetch the current state. Finally, poll the CopyStatus in a loop until it is no longer Pending.
The correct sequence begins with initializing the container client, followed by getting the specific blob client. Next, the copy is triggered from the destination blob client pointing to the source URI. Finally, the status is monitored by fetching the destination blob properties and polling until the copy status leaves the pending state.

Step-by-Step Solution

1
Instantiate the BlobContainerClient.
Establishes connection capabilities to the target container.
You must have a container client reference to acquire a reference to a specific blob in that container.
2
Retrieve the destination BlobClient.
Provides a client reference for the specific blob to be created or overwritten by the copy operation.
Copy operations are initiated on the destination blob client directly.
3
Call StartCopyFromUriAsync using the source URI.
Triggers the asynchronous copy operation on the Azure side, returning a copy ID.
The destination blob must pull the data from the source URI using the Storage service copy engine.
4
Call GetPropertiesAsync on the destination client.
Populates the BlobProperties object containing the CopyStatus.
You need to retrieve the latest state from Azure to check if the operation has already completed or is still running.
5
Check the CopyStatus value and poll in a loop.
Ensures the application waits for the operation to resolve to Success, Failed, or Aborted.
Because copying is asynchronous, the copy status must be checked iteratively until it is no longer pending.

Key Concept

Using Azure.Storage.Blobs SDK to copy blobs asynchronously from a source URI and monitor the copy status.
Rate this question