gpt4 book ai didi

c# - 指定的资源名称包含无效字符 即使 Blob 名称有效,为 Blob 生成 SAS url 时也会出错

转载 作者:行者123 更新时间:2023-12-03 02:13:06 25 4
gpt4 key购买 nike

我正在尝试通过 Web api 为 blob 创建 Sas Url但我不断收到此错误。我用过this blog post作为引用,但改变了一些我不需要的东西。(我已经尝试完全按照帖子所说的操作,复制粘贴,仍然不起作用)

这是我的代码:

var container = _blobServiceClient.GetBlobContainerClient("Files");
var client = container.GetBlobClient("dev-test/test-json.txt");
// I've tried to use just the name of the blob without the file extension and that doesn't work either

if (!client.CanGenerateSasUri)
return string.Empty;

var builder = new BlobSasBuilder
{
BlobContainerName = container.Name,
BlobName = client.Name,
Resource = "b",
StartsOn = DateTime.UtcNow,
ExpiresOn = DateTime.UtcNow.AddDays(1),
Protocol = SasProtocol.Https
};

builder.SetPermissions(BlobSasPermissions.Read);

Uri sasUri = client.GenerateSasUri(builder);
string url = sasUri.ToString();
return await Task.FromResult(url);

根据我见过的示例,我得到的网址似乎没问题,但是当我尝试访问该网址时,我收到标题中提到的错误。

当我在 azure 容器本身内使用“生成 SAS”时,它工作正常。但通过我的代码却没有。

这是我单击“生成 SAS”时从 azure blob 获得的 token :

sp=r&st=2022-06-12T21:00:00Z&se=2022-06-13T21:00:00Z&spr=https&sv=2021-06-08&sr=b&sig=2RhYyiWMGQxzidNQgsVFaiNJRDhRCKmHkQRnHM3x7J8%3D

这是我通过 api 请求获得的 token :

sv=2021-06-08&spr=https&st=2022-06-13T11%3A13%3A56Z&se=2022-06-14T11%3A13%3A56Z&sr=b&sp=r&sig=1Ttgdeti6NC8vcINmCNBQL7ejdE0ajNHhJRGAdGNANg%3D

最佳答案

容器名称也应该小写

var container = _blobServiceClient.GetBlobContainerClient("files");

关于c# - 指定的资源名称包含无效字符 即使 Blob 名称有效,为 Blob 生成 SAS url 时也会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72602009/

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