Question

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

You are developing a background service in C# that uses the .NET Azure.Storage.Blobs SDK to migrate public assets to a secure container. You need to copy a blob named video.mp4 from a public source container to a destination container in your storage account. The copy operation must run asynchronously, and the service must monitor the progress until it is fully completed.

Arrange the steps in the correct order to perform the copy and monitor its status.

  1. 1Instantiate a BlobServiceClient using the connection string of the destination storage account.
  2. 2Retrieve a BlobContainerClient for the destination container, and get a reference to the target BlobClient.
  3. 3Call StartCopyFromUriAsync on the target BlobClient, passing the URI of the public source blob.
  4. 4Call GetPropertiesAsync on the target BlobClient to fetch the initial copy operation details.
  5. 5Check the CopyStatus property of the returned properties in a loop until it does not equal CopyStatus.Pending.

Answer

First, instantiate the BlobServiceClient. Next, retrieve the destination BlobContainerClient and get a reference to the destination BlobClient. Then, call StartCopyFromUriAsync on the destination BlobClient using the source URI. Afterward, call GetPropertiesAsync to retrieve the initial status. Finally, poll the CopyStatus property in a loop until it is no longer pending.
The correct sequence begins with creating the client connection, accessing the destination container and blob references, initiating the copy from the source URI, and then polling the status properties until the operation is no longer pending.

Step-by-Step Solution

1
Instantiate the BlobServiceClient.
A service client is created to communicate with the target Azure Storage Account.
Establishing a service client is the prerequisite step for obtaining container and blob client references.
2
Retrieve references to the destination BlobContainerClient and BlobClient.
Client objects representing the destination container and the target blob are initialized.
You must obtain a reference to the specific target blob client to execute the copy method on it.
3
Call StartCopyFromUriAsync on the target BlobClient.
The asynchronous copy operation is initiated on the Azure Storage side.
This triggers the destination storage service to start copying data from the specified source URI.
4
Call GetPropertiesAsync on the target BlobClient.
The current metadata and state of the target blob are fetched.
The copy operation runs asynchronously on the server, so you must query the blob properties to find the status of the copy.
5
Poll the CopyStatus property in a loop.
The loop terminates once the copy status transitions to Succeeded, Failed, or Aborted.
This ensures the application waits until the background copy is fully resolved before performing subsequent logic.

Key Concept

Asynchronous blob copying and status monitoring using the .NET Azure.Storage.Blobs SDK
Rate this question