简体   繁体   English

Azure禁止Blob,但让Blob可以正常使用REST API

[英]Azure put blob forbidden, but get blob works rest api

I want to put a text file to a blob container using HttResquestMessage, and I get 403 error(Forbidden). 我想使用HttResquestMessage将文本文件放到Blob容器中,并且出现403错误(禁止访问)。 I know that this is a famous problem, and there are a lot of answers about it, but I've searched a lot and couldn't find the problem in my case. 我知道这是一个著名的问题,对此有很多答案,但是我进行了很多搜索,在我的情况下找不到问题。 Here is my Signature 这是我的签名

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"

And this is Authorization generated by SHA256 and Base64 encoding 这是由SHA256Base64编码生成的授权

SharedKey MyStorage:Oy8nB79/KVROzxYCYSF71djhIwYEYS36tgRqyxe6sXY=

This Authorization works for GET request I've tried to get all container names and it succeeded. 此授权适用于GET请求,我尝试获取所有容器名称,但成功。

My HttpRequestMessage looks like 我的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}

What I missed in the request? 我在请求中错过了什么?

Two parameters need adding when putting blob 放入Blob时需要添加两个参数

  • x-ms-blob-type is required to be included in HttpRequestMessage header. x-ms-blob-type必须包含在HttpRequestMessage标头中。
  • Content-MD5 is optional, but if you add it in your request header, it should also be included in StringToSign, ie the Signature you mentioned. Content-MD5是可选的,但是如果将其添加到请求标头中,则它也应该包含在StringToSign中,即您提到的签名。

Any further question, just ask. 还有其他问题,问一下即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM