CloudBlob.BeginCopyFromBlob Method (CloudBlob, BlobRequestOptions, AsyncCallback, Object)

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Begins an asynchronous operation to copy another blob's contents, properties, and metadata to the blob referenced by this CloudBlob object.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

Usage

Visual Basic
Dim instance As CloudBlob
Dim source As CloudBlob
Dim options As BlobRequestOptions
Dim callback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginCopyFromBlob(source, options, callback, state)

Syntax

Visual Basic
Public Function BeginCopyFromBlob ( _
	source As CloudBlob, _
	options As BlobRequestOptions, _
	callback As AsyncCallback, _
	state As Object _
) As IAsyncResult
C#
public IAsyncResult BeginCopyFromBlob (
	CloudBlob source,
	BlobRequestOptions options,
	AsyncCallback callback,
	Object state
)
C++
public:
IAsyncResult^ BeginCopyFromBlob (
	CloudBlob^ source, 
	BlobRequestOptions^ options, 
	AsyncCallback^ callback, 
	Object^ state
)
J#
JScript

Parameters

source

Type: Microsoft.WindowsAzure.StorageClient.CloudBlob

The source blob.

options

Type: Microsoft.WindowsAzure.StorageClient.BlobRequestOptions

An object that specifies any additional options for the request.

callback

Type: System.AsyncCallback

The callback delegate that will receive notification when the asynchronous operation completes.

state

Type: System.Object

A user-defined object that will be passed to the callback delegate.

Return Value

Type: System.IAsyncResult

An IAsyncResult that references the asynchronous operation.

Example

The following code example creates a new blob and copies it to a second blob, while specifying a particular request option.

C# Copy Code
static void CopyBlobAsync(Uri blobEndpoint, string accountName, string accountKey)
{
    // Create service client for credentialed access to the Blob service.
    CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));

    // Create a new blob by uploading a file.
    CloudBlob sourceBlob = blobClient.GetBlobReference("mycontainer/sourceblob.txt");
    sourceBlob.UploadFile("C:\\somefile.txt");

    // Get a reference to the destination blob.
    CloudBlob destBlob = blobClient.GetBlobReference("mycontainer/destblob.txt");

    // Set options for the request.
    // E.g., Copy only if the source blob has changed during the past week.
    System.TimeSpan interval = new TimeSpan(7, 0, 0, 0);
    BlobRequestOptions options = new BlobRequestOptions();
    options.CopySourceAccessCondition = AccessCondition.IfModifiedSince(DateTime.UtcNow.Subtract(interval));

    destBlob.BeginCopyFromBlob(sourceBlob, options, CopyBlobCallback, destBlob);
}

static void CopyBlobCallback(IAsyncResult result)
{
    CloudBlob blobDest = (CloudBlob)result.AsyncState;

    // End the operation.
    blobDest.EndCopyFromBlob(result);
}

Remarks

The BeginCopyFromBlob method begins an operation to copy the source blob specified in the source parameter to the blob on which this method is called (the destination blob).

Copying a source blob always copies the entire blob; copying a range of bytes or a set of blocks is not supported.

A blob copy operation can take any of the following forms:

  • You can copy a source blob to a destination blob with a different name from that of the source blob. The destination blob can be an existing blob, or a new blob created by the copy operation.

  • You can copy a snapshot over its base blob. By promoting a snapshot to the position of the base blob, you can restore an earlier version of a blob.

  • You can copy a snapshot to a destination blob with a different name. The resulting destination blob is a writeable blob and not a snapshot.

Copying Blob Properties and Metadata

When a blob is copied, the following system properties are copied to the destination blob with the same values:

The source blob's committed block list is also copied to the destination blob, if the blob is a block blob. Any uncommitted blocks are not copied.

Copying Conditionally

You can specify an access condition to copy the blob only if a condition is met. To specify a condition on the destination blob, use the AccessCondition property. To specify a condition on the source blob, use the CopySourceAccessCondition property. If the specified condition is not met, the blob is not copied, and the Blob service returns HTTPStatusCode.PreconditionFailed.

Copying a Leased Blob

To copy a leased blob, use the CopyFrom method.

Copying Snapshots

When a source blob is copied, any snapshots of the source blob are not copied to the destination. When a destination blob is overwritten with a copy, any snapshots associated with the destination blob stay intact under its name.

You can perform a copy operation to promote a snapshot blob over its base blob. In this way you can restore an earlier version of a blob. The snapshot remains, but its source is overwritten with a copy that can be both read and written.


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also