Azure Powershell - 如何使用 "write-only" 共享访问签名 (SAS) 将文件上传到 Blob 存储?

Azure Powershell - How to upload file to Blob Storage using "write-only" shared access signature (SAS)?

我已经尝试了一段时间了。这是我的 Powershell:

$storSas = "sas-generated-with-windows-storage-explorer"
$StorageAccountName = "storageacc"
$containerName = "some-cont-name"
$clientContext = New-AzureStorageContext -SasToken $storSAS -StorageAccountName $StorageAccountName

# upload a file
Set-AzureStorageBlobContent -File "F:\somefile" `
  -Container $containerName `
  -Blob "somefile" `
  -Context $ClientContext 

每次我得到:

The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error Message: This re quest is not authorized to perform this operation using this permission.

我的策略具有写入和列表权限,为什么会出现此错误?

有 2 个问题:

  1. 请使用 https://github.com/Azure/azure-powershell/releases 的最新 Azure Powershell(当前为 6.9.0)

  2. 如果您需要在没有读取权限的情况下使用 SAS 上传 blob,需要将 -Force 添加到 Set-AzureStorageBlobContent cmdlet。这是因为默认情况下我们会检查dest blob是否存在(需要读权限),如果dest blob存在则提醒用户weather覆盖。

以下脚本适合我: $sas = New-AzureStorageBlobSASToken -container $containerName -Blob $blobname -Permission w -Context $ctxkey $ctxsas = New-AzureStorageContext -StorageAccountName $StorageAccountName -SasToken $sas $a = Set-AzureStorageBlobContent -File $localSrcFile -Container $containerName -Blob $blobname -Force -Context $ctxsas

除此之外,如果您使用最新版本的 Azure Powershell,Get-AzureStorageContainer 也适用于 SAS。 (反正容器ACL获取不到,需要key权限)