如何为 (REST API) 天蓝色存储 SAS(共享访问签名)构建 header

how to construct header for (REST API) azure storage SAS (shared accesss signature)

我正在调试一个调用 REST API 嵌入了 AZURE 存储 SAS-shared 访问签名的客户端应用程序来访问 azure 存储资源。但是,它没有通过。天蓝色抛出了一个错误,指出缺少必需的header,并中止操作。

REST API 相当简单,尽管它嵌入了 Azure 存储帐户生成的 SAS 令牌。客户端应用程序使用 REST API 将数据写入 azure blob。

有什么地方可以找到一个很好的例子来说明如何为 REST API (SAS) 生成 header?我需要找出 header 的确切布局(例如 header.

中需要嵌入的信息类型

此外,我是否需要向 Azure AD 注册我的客户端应用程序?

我认为我的客户端应用程序不需要向 AZURE 注册,因为这就是我们拥有 client-side SAS 的原因。但是,我可能是错的。因此,我们将不胜感激。

提前致谢。

如果您使用 sas 令牌调用 Azure blob rest api,请求 URL 应该像

https://myaccount.blob.core.windows.net/<cantianer>/<blob>?<sastoken>

例如

$accountName=""
$accountKey=""
$containerName="output"
$blobName="test.txt"


$context= New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey
$sas = New-AzStorageAccountSASToken -Service Blob -ResourceType Service,Container,Object -Permission "rwdlacx" -Context $context

$body = "Hello"

$headers=@{"x-ms-blob-type"="BlockBlob"; "Content-Type"="text/plain"}

$url="https://$accountName.blob.core.windows.net/$containerName/$blobName$sas"

 Invoke-WebRequest -Uri $url -Method Put -Headers $headers -Body $body -UseBasicParsing