简体   繁体   English

Azure Powershell-如何使用“仅写”共享访问签名(SAS)将文件上传到Blob存储?

[英]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: 有两个问题:

  1. 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)

  2. 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.

相关问题 使用 SAS(共享访问签名)使用 Azure 存储上传文件 - Upload file with Azure Storage using SAS (Shared Access Signature) Azure Blob 存储共享访问签名 (SAS) - 签名不匹配 - Azure Blob Storage Shared Access Signature (SAS) - Signature did not match 是否可以在azure blob存储中为给定目录生成具有写许可权的SAS(共享访问签名) - Is it possible to generate SAS (Shared Access Signature) with write permission for given directory in azure blob storage 如何使用 Powershell 和共享访问签名在 Azure blob 容器中列出文件、删除文件、写入文件 - How to to list files, delete files, write files, in an Azure blob container using Powershell and Shared Access Signature 使用Powershell为Azure云存储帐户创建共享访问签名(SAS) - Create a Shared Access Signature (SAS) for an Azure Cloud Storage Account with powershell 使用带有共享访问签名的 Rest API 上传到 Blob 存储 - Upload via to Blob Storage using Rest API with Shared Access Signature 在img标签中为Azure Blob存储使用共享访问签名Uri - Using Shared Access Signature Uri in img tag for Azure Blob Storage 如何为 Azure blob 存储中的文件夹生成共享访问签名? - How to generate a Shared access signature for a folder in Azure blob storage? 使用Node.js Azure存储为一个文件生成共享访问签名(SAS) - Generate Shared Access Signature (SAS) for one file using nodejs azure storage Azure存储的只写访问权限(无读取,无列表,无删除) - Write-Only access (no read, no list, no delete) to Azure Storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM