gpt4 book ai didi

azure - CloudPageBlob StartCopyAsync 失败,状态为 404

转载 作者:行者123 更新时间:2023-12-04 15:33:25 25 4
gpt4 key购买 nike

我在尝试将 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;
}

调用返回{“远程服务器返回错误:(404)未找到。”}但是,如果我调用 sourcePageBlob.Exists() 它会返回 true

最佳答案

拥有一个私有(private)源容器是问题所在。您需要获取一个共享访问 URI,该 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;
}

关于azure - CloudPageBlob StartCopyAsync 失败,状态为 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41579670/

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