【问题标题】:Azure put blob forbidden, but get blob works rest apiAzure 禁止使用 blob,但获取 blob 工作休息 api
【发布时间】:2018-10-21 13:02:15
【问题描述】:

我想使用 HttResquestMessage 将文本文件放入 blob 容器,但出现 403 错误(禁止访问)。 我知道这是一个著名的问题,并且有很多关于它的答案,但是我搜索了很多,找不到我的问题。 这是我的签名

PUT\n
\n
\n
11\n
\n
\n
\n
\n
\n
\n
\n
\n
x-ms-blob-type:BlockBlob\n
x-ms-date:Thu, 10 May 2018 16:00:21 GMT\n
x-ms-version:2017-07-29\n
/MyStorage/dbstore/myFolder/test2.txt"

这是SHA256Base64编码生成的授权

SharedKey MyStorage:Oy8nB79/KVROzxYCYSF71djhIwYEYS36tgRqyxe6sXY=

此授权适用于 GET 请求我已尝试获取所有容器名称并成功。

我的 HttpRequestMessage 看起来像

{Method: PUT, RequestUri:             
'http://MyStorage.blob.core.windows.net/dbstore/            
myFolder/test2.txt', Version: 1.1, Content: 
System.Net.Http.ByteArrayContent, Headers:
{
  x-ms-date: Fri, 11 May 2018 06:39:35 GMT
  x-ms-version: 2017-07-29
  Authorization: SharedKey     
storagekaren:Oy8nB79/KVROzxYCYSF71djhIwYEYS36tgRqyxe6sXY=
  Content-Length: 11
  Content-MD5: CAQ66JnJH0H9GhrLTy+b1w==
}}
    Content: {System.Net.Http.ByteArrayContent}
    Headers: {x-ms-date: Fri, 11 May 2018 06:39:35 GMT
x-ms-version: 2017-07-29
Authorization: SharedKey     
storagekaren:Oy8nB79/KVROzxYCYSF71djhIwYEYS36tgRqyxe6sXY=
}
    Method: {PUT}
    Properties: Count = 0
    RequestUri: {http://MyStorage.blob.core.windows.net/dbstore/myFolder/test2.txt}
    Version: {1.1}

我在请求中遗漏了什么?

【问题讨论】:

    标签: c# rest azure httprequest azure-blob-storage


    【解决方案1】:

    放置blob时需要添加两个参数

    • x-ms-blob-type 必须包含在 HttpRequestMessage 标头中。
    • Content-MD5 是可选的,但如果你在请求头中添加它,它也应该包含在 StringToSign 中,即你提到的 Signature。

    还有什么问题,尽管问。

    【讨论】:

    • 非常感谢,这是我的问题。
    猜你喜欢
    • 2021-07-08
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    • 2019-12-20
    • 2020-12-09
    • 2016-02-11
    • 1970-01-01
    • 2018-05-07
    相关资源
    最近更新 更多