当前位置:  开发笔记 > 运维 > 正文

CloudPageBlob StartCopyAsync失败,状态为404

如何解决《CloudPageBlobStartCopyAsync失败,状态为404》经验,为你挑选了1个好方法。

我遇到了一个问题,我试图将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.



1> Michael Sabi..:

拥有私有源容器是个问题.您需要获取一个共享访问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;
}

推荐阅读
殉情放开那只小兔子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有