gpt4 book ai didi

c# - Azure Blob 存储 Sas 错误 : AuthenticationFailed

转载 作者:行者123 更新时间:2023-12-03 02:46:21 24 4
gpt4 key购买 nike

我正在尝试在 Azure Blob 存储中使用 SAS token ,如下 this tutorial ,但我遇到了这个错误:

<Error>
<Code>AuthenticationFailed</Code>
<Message>
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:2aada4ff-901e-0011-116c-8bc84f000000 Time:2019-10-25T19:41:37.0381744Z
</Message>
<AuthenticationErrorDetail>
Signature did not match. String to sign used was r 2019-10-25T19:26:51Z 2019-10-25T20:31:51Z /blob/platinepersistencesg/$root/documents-legal-entity-01d6d631-bc1e-54e7-894e-f67297a2bae7 2019-02-02 b
</AuthenticationErrorDetail>
</Error>

这是我的代码:

public async Task<IActionResult> GetSasToken()
{
const string containerName = "documents-legal-entity-01d6d631-bc1e-54e7-894e-f67297a2bae7";
const string blobName = "09578f41-e7fb-4765-bf41-869ea649f03a.pdf";
const SharedAccessBlobPermissions permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Create;

var blobClient = CloudStorageAccount
.Parse("DefaultEndpointsProtocol=https;AccountName=<account_name>;AccountKey=<account_key>;EndpointSuffix=core.windows.net")
.CreateCloudBlobClient();

var container = blobClient.GetContainerReference(containerName);
var blob = container.GetBlockBlobReference(blobName);
var policy = new SharedAccessBlobPolicy
{
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
Permissions = permissions
};
var sasToken = blob.GetSharedAccessSignature(policy);
var sasUri = container.Uri + sasToken;

return Ok(new { uri = sasUri });
}

我能够按照 this answer 使其工作,但为了简单起见,我想改用 Azure 客户端,并避免携带存储 key 。

最佳答案

您唯一缺少的是 URL 构造中的 blob 名称。只需要更改:

var sasUri = 容器.Uri + sasToken;

...到...

var sasUri = blob.Uri + sasToken;

关于c# - Azure Blob 存储 Sas 错误 : AuthenticationFailed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58565283/

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