匯出 (0) 列印
全部展開

CloudBlob.CopyFromBlob 方法 (CloudBlob)

Copies an existing blob's contents, properties, and metadata to a new blob.

命名空間: Microsoft.WindowsAzure.StorageClient
組件: Microsoft.WindowsAzure.StorageClient (在 microsoft.windowsazure.storageclient.dll 中)

'用途
Dim instance As CloudBlob
Dim source As CloudBlob

instance.CopyFromBlob(source)

'宣告
Public Sub CopyFromBlob ( _
	source As CloudBlob _
)
public void CopyFromBlob (
	CloudBlob source
)
public function CopyFromBlob (
	source : CloudBlob
)

參數

source

The source blob.

The following code example checks an access condition on the source blob and copies the blob if the condition is met.

static void CopyIfModifiedSince(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));

    //Get a reference to the source blob.
    CloudBlob sourceBlob = blobClient.GetBlobReference("mycontainer/myblob.txt");
    sourceBlob.FetchAttributes();

    //Get a reference to the destination blob.
    CloudBlob destBlob = blobClient.GetBlobReference("mycontainer/copy-if-modified-since.txt");
    BlobRequestOptions options = new BlobRequestOptions();
    DateTime dt = new DateTime(2010, 9, 1, 0, 0, 0, DateTimeKind.Utc);

    try
    {
        //Copy the source blob to the destination blob if the source blob has been modified since 9/1/2010.
        options.CopySourceAccessCondition = AccessCondition.IfModifiedSince(dt.ToUniversalTime());
        destBlob.CopyFromBlob(sourceBlob, options);
    }
    catch (StorageClientException e)
    {
        if (e.StatusCode == HttpStatusCode.PreconditionFailed)
        {
            Console.WriteLine("Access condition not met - blob " + sourceBlob.Uri + " has not been modified since " + dt.ToUniversalTime());
        }
        else
        {
            Console.WriteLine("Error code: " + e.ErrorCode);
        }
    }
}

The CopyFromBlob method copies 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 source blob to a destination blob with the same name, effectively replacing the source blob. Such a copy operation removes any uncommitted blocks and overwrites the blob's metadata.

  • 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, using the overload that takes an options parameter. 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.


任何這個類型的公用靜態 (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。 並非所有的執行個體成員都是安全執行緒。

開發平台

Windows XP Home Edition, Windows XP Professional, Windows Server 2003、Windows Server 2008 和 Windows 2000

目標平台

社群新增項目

Microsoft 正展開一份線上問卷調查,了解您對於 MSDN 網站的看法。 如果您選擇參加,您離開 MSDN 網站時即會顯示線上問卷調查。

您是否想要參加?
顯示:
© 2014 Microsoft