Azure的BLOB授权头 [英] Azure blob authorization header
问题描述
我试图使用改装上传到从Xamarin的iOS应用程序蔚蓝Blob存储。这是接口的配置我使用了改装:
[标题(X-MS-BLOB类型:BlockBlob)]
[放(/ {文件名})]
任务<布尔> UploadAsync([正文]字节[]的内容,串sasTokenKey,
[标题(内容类型)]串的contentType);
凡sasTokenKey参数如下:
<$p$p><$c$c>\"/content-default/1635839001660743375-66f93195-e923-4c8b-a3f1-5f3f9ba9dd32.jpeg?sv=2015-04-05&sr=b&sig=Up26vDxQikFqo%2FDQjRB08YtmK418rZfKx1IHbYKAjIE%3D&se=2015-11-23T18:59:26Z&sp=w\"这是我如何使用改装调用蔚蓝色的斑点服务器:
VAR myRefitApi = RestService.For&LT; IMyRefitAPI&GT;(https://myaccount.blob.core.windows.net);
myRefitApi.UploadAsync(photoBytes,sasTokenKey,图像/ JPEG
但是我收到如下错误:
响应状态code并不表示成功:403(服务器失败
验证请求。确保授权头的值
形成正确包括签名。)
在SAS网址是工作的罚款,如果我直接调用它像这样
VAR内容=新StreamContent(流);
content.Headers.Add(内容类型,JPEG);
content.Headers.Add(X-MS-斑点型,BlockBlob);
VAR任务= HttpClient.PutAsync(新的URI(sasTokenUrl),内容);
task.Wait();
所以基本上我只是试图做重新安装使用同样的事情。
任何想法如何获得与重新安装的Azure Blob存储工作?
谢谢!
[更新]我现在能字节上传到蔚蓝色的斑点服务器,但有些事情似乎因为我无法查看图像是错误的字节数据。这里是code我使用转换为字节数组。
字节[]字节;
使用(VAR毫秒=新的MemoryStream())
{
stream.Position = 0;
stream.CopyTo(毫秒);
ms.Position = 0;
字节= ms.ToArray();
}
[更新]得到了它的固定使用,而不是字节数组流!
我看到%2F%和3D,我很好奇,如果改装是这些编码第二次。试着发送令牌没有对其进行编码。
I am trying to use refit to upload to azure blob storage from a Xamarin iOS application. This is the interface configuration I am using for Refit:
[Headers("x-ms-blob-type: BlockBlob")]
[Put("/{fileName}")]
Task<bool> UploadAsync([Body]byte[] content, string sasTokenKey,
[Header("Content-Type")] string contentType);
Where the sasTokenKey parameter looks like this:
"/content-default/1635839001660743375-66f93195-e923-4c8b-a3f1-5f3f9ba9dd32.jpeg?sv=2015-04-05&sr=b&sig=Up26vDxQikFqo%2FDQjRB08YtmK418rZfKx1IHbYKAjIE%3D&se=2015-11-23T18:59:26Z&sp=w"
This is how I am using Refit to call the azure blob server:
var myRefitApi = RestService.For<IMyRefitAPI>("https://myaccount.blob.core.windows.net");
myRefitApi.UploadAsync(photoBytes, sasTokenKey, "image/jpeg"
However I am getting the follow error:
Response status code does not indicate success: 403 (Server failed to
authenticate the request. Make sure the value of Authorization header is
formed correctly including the signature.)
The SAS url is working fine if I call it directly like this
var content = new StreamContent(stream);
content.Headers.Add("Content-Type", "jpeg");
content.Headers.Add("x-ms-blob-type", "BlockBlob");
var task = HttpClient.PutAsync(new Uri(sasTokenUrl), content);
task.Wait();
So basically I am just trying to do the same thing using Refit. Any idea how to get Refit working with Azure Blob Storage?
Thanks!
[UPDATE] I am now able to upload the bytes to the azure blob server but something seems to be wrong with the byte data because I am not able to view the image. Here is the code I am using to convert to byte array.
byte[] bytes;
using (var ms = new MemoryStream())
{
stream.Position = 0;
stream.CopyTo(ms);
ms.Position = 0;
bytes = ms.ToArray();
}
[UPDATE] Got it fixed by using stream instead of byte array!
I see %2F and %3D and I'm curious if refit is encoding those a second time. Try sending the token without encoding it.
这篇关于Azure的BLOB授权头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!