gpt4 book ai didi

c# - Azure Blob 存储身份验证错误为子文件夹中的 blob 创建 SAS

转载 作者:行者123 更新时间:2023-12-03 02:50:14 26 4
gpt4 key购买 nike

我使用以下代码让用户通过共享访问签名 (SAS) 访问我的 Blob 存储中的单个文件:

            var container = _blobClient.GetContainerReference(containerPath[0]);
var blob = container.GetBlockBlobReference(blobName);

var policy = new SharedAccessBlobPolicy()
{
SharedAccessStartTime = DateTimeOffset.UtcNow,
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
Permissions = SharedAccessBlobPermissions.Read
};

var blobHeaders = new SharedAccessBlobHeaders();
var sasToken = blob.GetSharedAccessSignature(policy, blobHeaders);

return blob.Uri.AbsoluteUri + sasToken;

我正在创建的 token 已创建,但它不起作用,我收到以下错误:

Signature did not match. String to sign used was r 2019-06-07T09:19:05Z 2019-06-08T09:19:05Z /blob/X/filestore/images/company/X.jpeg 2018-11-09 b

其中 filestore/images/company/ 是目录,X.jpeg 是我的文件名。我的 blob 容器是私有(private)的。

我已经尝试了针对类似主题的问题提供的大部分选项,但不确定我哪里出错了。我通过 Azure 门户为这个 blob 创建了一个共享访问签名,它工作得很好。有什么想法吗?

最佳答案

通过尝试获取上述容器对象的属性,我发现在 Azure 存储中找不到我的容器和文件。这很奇怪,因为文件路径是正确的。在浏览时我发现了这个answer :

There is actually only a single layer of containers. You can virtually create a "file-system" like layered storage, but in reality everything will be in 1 layer, the container in which it is.

For creating a virtual "file-system" like storage, you can have blob names that contain a '/' so that you can do whatever you like with the way you store. Also, the great thing is that you can search for a blob at a virtual level, by giving a partial string, up to a '/'.

这意味着对于我的 blob (filestore/images/company/x.jpg),容器只是 filestore 并且 blob 名称是 images/company/x.jpg 尽管 Azure 门户显示子文件夹,但实际结构是扁平的。

一旦我了解了这一点,我就能够以完全相同的方式创建我的共享访问签名,但这次成功了。

关于c# - Azure Blob 存储身份验证错误为子文件夹中的 blob 创建 SAS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56495411/

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