![](/img/trans.png)
[英]Microsoft.Azure.StorageException: The specified resource name contains invalid characters
[英]The specified resource name contains invalid characters Error generating SAS url for blob even though blob name is valid
我正在嘗試通過 web api 為 blob 創建一個 Sas Url,但我不斷收到此錯誤。 我已將此博客文章用作參考,但更改了一些我不需要的東西。 (我試過完全按照帖子說的做,復制粘貼,還是不行)
這是我的代碼:
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);
根據我看到的示例,我得到一個似乎很好的 url,但是當我嘗試訪問該 url 時,我得到了標題中提到的錯誤。
當我在 azure 容器本身內使用 Generate SAS 時,它工作正常。 但通過我的代碼它沒有。
這是我單擊生成 SAS 時從 azure blob 獲得的令牌:
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 請求獲得的令牌:
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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.