0
votes

From the documentation of the function CloudBlobClient.StartCopyAsync()

It says

Initiates an asynchronous operation to start copying another block blob's contents, properties, and metadata to this block blob.

I hope to know if the function will return once the process is started, or completed. If the implementation of this function open-sourced?

It's a partial class here: https://github.com/Azure/azure-storage-net/blob/master/Lib/WindowsRuntime/Blob/CloudBlobClient.cs

1

1 Answers

2
votes

Internally, CloudBlockBlob.StartCopyAsync() calls the Copy Blob REST API.

The function will return once the process is started:

In version 2012-02-12 and newer, the Copy Blob operation can complete asynchronously. This operation returns a copy ID you can use to check or abort the copy operation. The Blob service copies blobs on a best-effort basis.

The source blob for a copy operation may be a block blob, an append blob, or a page blob, or a snapshot. If the destination blob already exists, it must be of the same blob type as the source blob. Any existing destination blob will be overwritten. The destination blob cannot be modified while a copy operation is in progress.

In version 2015-02-21 and newer, the source for the copy operation may also be a file in the Azure File service. If the source is a file, the destination must be a block blob.

Below is the source code to proactively check copy status after calling CloudBlockBlob.StartCopyAsync():

await targetCloudBlob.StartCopyAsync(sourceCloudBlob.Uri);

while (targetCloudBlob.CopyState.Status == CopyStatus.Pending)
{
    await Task.Delay(100);
    await targetCloudBlob.FetchAttributesAsync();
}

if (targetCloudBlob.CopyState.Status != CopyStatus.Success)
{
    Console.WriteLine("Copy failed: {0}", targetCloudBlob.CopyState.Status);
}