[英]Azure Powershell - How to upload file to Blob Storage using “write-only” shared access signature (SAS)?
I've been trying this for some time now. 我已经尝试了一段时间了。 Here's my Powershell:
这是我的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
And every time I get: 每当我得到:
The remote server returned an error: (403) Forbidden.
远程服务器返回错误:(403)禁止。 HTTP Status Code: 403 - HTTP Error Message: This re quest is not authorized to perform this operation using this permission.
HTTP状态代码:403-HTTP错误消息:未经授权,此请求无权执行此操作。
My policy has Write and List permissions, why do I get this error? 我的策略具有“写入”和“列表”权限,为什么会出现此错误?
There are 2 issues: 有两个问题:
Please use the latest Azure Powershell from https://github.com/Azure/azure-powershell/releases (currently is 6.9.0) 请使用https://github.com/Azure/azure-powershell/releases中的最新Azure Powershell(当前为6.9.0)
If you need upload blob with SAS without Read permission, need add -Force
to Set-AzureStorageBlobContent
cmdlets. 如果您需要具有SAS且没有读取权限的上载blob,则需要将
-Force
添加到Set-AzureStorageBlobContent
cmdlet。 This is because by default we will check if the dest blob exist (need read permission), and remind user weather to overwrite if dest blob exist. 这是因为默认情况下,我们将检查dest blob是否存在(需要读取权限),并提醒用户天气是否存在dest blob覆盖。
The following script works for me: $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
以下脚本为我工作:
$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
Besides that, if you use the latest version of Azure Powershell, Get-AzureStorageContainer also works with SAS. 除此之外,如果您使用最新版本的Azure Powershell,Get-AzureStorageContainer也可以与SAS一起使用。 (Anyway, container ACL can't be get since need key permission)
(无论如何,由于需要密钥许可,因此无法获取容器ACL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.