【问题标题】:Azure Resource Manager .NET SDK, copying VHDs/BlobsAzure 资源管理器 .NET SDK,复制 VHD/Blob
【发布时间】:2017-04-04 00:17:53
【问题描述】:

我正在尝试找到一种方法将 VHD 复制到我的资源组中的存储帐户。

我有一个 VHD 的 Sas Uri。

我会使用 Powershell:

Start-AzureStorageBlobCopy `
-AbsoluteUri $sas.AccessSAS `
-DestContainer 'vhds' -DestContext $destContext -DestBlob 'MyDestinationBlobName.vhd'

这样做。

我似乎无法从 Azure 资源管理器的 .NET SDK 中找到方法。 https://github.com/Azure/azure-sdk-for-net/tree/AutoRest/src/ResourceManagement/

有什么方法可以使用 .NET 复制 blob?

【问题讨论】:

    标签: .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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多