Azure 资源管理器 .NET SDK,正在复制 VHDs/Blobs
Azure Resource Manager .NET SDK, copying VHDs/Blobs
我正在尝试找到一种方法将 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?
您需要使用 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);
}
我正在尝试找到一种方法将 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?
您需要使用 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);
}