我正在使用此代码将 blob 从一个帐户复制到另一个帐户……但它会引发异常。
var srcAccount = CloudStorageAccount.Parse("connection string 1");
var dstAccount = CloudStorageAccount.Parse("connection string 2");
var srcBlobClient = srcAccount.CreateCloudBlobClient();
var dstBlobClient = dstAccount.CreateCloudBlobClient();
foreach (var srcCloudBlobContainer in srcBlobClient.ListContainers())
{
var dstCloudBlobContainer = dstBlobClient
.GetContainerReference(srcCloudBlobContainer.Name);
dstCloudBlobContainer.CreateIfNotExists();
foreach (var srcBlob in srcCloudBlobContainer.ListBlobs())
{
if (srcBlob.GetType() == typeof(CloudBlockBlob))
{
var srcBlockBlock = (CloudBlockBlob)srcBlob;
var dstBlockBlock = dstCloudBlobContainer
.GetBlockBlobReference(srcBlockBlock.Name);
// throws exception StorageException:
// The remote server returned an error: (404) Not Found.
dstBlockBlock.StartCopyFromBlob(srcBlockBlock.Uri);
}
}
}
微软声明支持跨账户复制,但我无法让它工作。
我究竟做错了什么?