gpt4 book ai didi

azure - 无法通过 C# 中的 Rest API 在 Azure 存储上获取/发布 Blob

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

在 C# 代码中成功使用 Azure Rest api 后。我能够创建、获取和获取容器列表,但不能创建 blob。在访问或上传 blob 时,这会导致权限问题,即

you are not authorized to perform this request with assigned permission

到目前为止我取得的进展:

  1. 能够创建和获取容器。
  2. 能够获取存储帐户所有容器的列表。

当尝试通过下面的源代码获取/放置 blob 时,会出现错误:

This request is not authorized to perform this operation using this permission.

string endPointUri = $"{azureApplicationConfiguration.Resource}/{inpContainerName}/{inpBlobName}";
var request = (HttpWebRequest)WebRequest.Create(endPointUri);
request.Method = HTTPMethod.GET.ToString();
request.Headers.Add("Authorization", $"Bearer {sasToken.access_token}");
request.Headers.Add("x-ms-date", DateTime.UtcNow.ToString("R"));
request.Headers.Add("x-ms-version", "2018-03-28");
request.ProtocolVersion = HttpVersion.Version11;

using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
{
Console.WriteLine(resp.StatusCode.ToString());
Console.ReadKey();
}

最佳答案

最可能的答案是您用于身份验证的 SAS token 不支持对象级访问。您可以通过检查 Signed Resource Types 中是否有字母 o 来确认这一点。 SAS token 中的 srt= 参数。基于您可以列出和创建容器的事实,我猜测当前值是 srt=sc。为了能够对 blob 执行 GET/PUT 操作,您需要生成一个包含对象级别权限的新 SAS token ,该 token 应为您提供一个包含 srt=sco 的 token 。

<小时/>

如果您还不知道,有一个 .NET Azure Storage SDK可用,它提供了 REST API 的抽象层,从长远来看可能会节省您一些时间。

关于azure - 无法通过 C# 中的 Rest API 在 Azure 存储上获取/发布 Blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57674041/

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