gpt4 book ai didi

.net - Azure 资源管理器 .NET SDK,复制 VHD/Blob

转载 作者:行者123 更新时间:2023-12-03 07:48:39 26 4
gpt4 key购买 nike

我正在尝试找到一种方法将 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 吗?

最佳答案

Is there any way I can copy a blob using .NET?

您需要使用适用于 .Net 的 Azure 存储 SDK ( 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);
}

关于.net - Azure 资源管理器 .NET SDK,复制 VHD/Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43196338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com