【问题标题】:Azure Resource Manager .NET SDK, copying VHDs/BlobsAzure 资源管理器 .NET SDK,复制 VHD/Blob
【发布时间】:2017-04-04 00:17:53
【问题描述】:
【问题讨论】:
标签:
.net
azure
azure-blob-storage
vhd
【解决方案1】:
有什么方法可以使用 .NET 复制 blob?
您需要使用Azure Storage SDK for .Net (Github|Nuget)。
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
static void CopyBlobUsingSasExample()
{
var destinationAccountName = "";
var destinationAccountKey = "";
var destinationAccount = new CloudStorageAccount(new StorageCredentials(destinationAccountName, destinationAccountKey), true);
var destinationContainerName = "vhds";
var destinationContainer = destinationAccount.CreateCloudBlobClient().GetContainerReference(destinationContainerName);
destinationContainer.CreateIfNotExists();
var destinationBlob = destinationContainer.GetPageBlobReference("MyDestinationBlobName.vhd");
var sourceBlobSasUri = "";
destinationBlob.StartCopy(new Uri(sourceBlobSasUri));
//Since copy operation is async, please wait for the copy operation to finish.
do
{
destinationBlob.FetchAttributes();
var copyStatus = destinationBlob.CopyState.Status;
if (copyStatus != CopyStatus.Pending)
{
break;
}
else
{
System.Threading.Thread.Sleep(5000);//Sleep for 5 seconds and then fetch attributes to check the copy status.
}
} while (true);
}