我遇到了一个问题,我正在尝试将CloudPageBlob复制到另一个Azure订阅中的存储帐户。出于某种原因,当我进行复制调用时,我继续收到404错误:
CloudBlobContainer destContainer;
CloudBlob sourceBlob;
string destBlobName;
var sourcePageBlob = sourceBlob as CloudPageBlob;
if (sourcePageBlob != null)
{
var destBlob = destContainer.GetPageBlobReference(destBlobName);
await destBlob.StartCopyAsync(sourcePageBlob, AccessCondition.GenerateIfExistsCondition(), AccessCondition.GenerateEmptyCondition(), new BlobRequestOptions(), new OperationContext());
return destBlob;
}
通话回复{"The remote server returned an error: (404) Not Found."}
但是,如果我致电sourcePageBlob.Exists()
,则会返回true
。
答案 0 :(得分:6)
拥有私有源容器是个问题。您需要获取一个共享访问URI,允许目标存储帐户访问源存储帐户。这篇博客文章解释了它:https://alexandrebrisebois.wordpress.com/2013/06/25/copy-blobs-with-startcopyfromblob-and-track-its-progression-using-copystate/
CloudBlobContainer destContainer;
CloudBlob sourceBlob;
string destBlobName;
var sharedAccessUri = GetShareAccessUri(sourceBlob);
var sourcePageBlob = sourceBlob as CloudPageBlob;
if (sourcePageBlob != null)
{
var destBlob = destContainer.GetPageBlobReference(destBlobName);
await destBlob.StartCopyAsync(new Uri(sharedAccessUri));
return destBlob;
}
private string GetShareAccessUri(CloudBlob sourceBlob)
{
int validMins = 300;
var policy = new SharedAccessBlobPolicy
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessStartTime = null,
SharedAccessExpiryTime = DateTimeOffset.Now.AddMinutes(validMins)
};
var sas = sourceBlob.GetSharedAccessSignature(policy);
return sourceBlob.Uri.AbsoluteUri + sas;
}