生成Azure的共享访问签名与BlobService.getBlobURL()在Azure的SDK进行的Node.js [英] Generating Azure Shared Access Signatures with BlobService.getBlobURL() in Azure SDK for Node.js

查看:159
本文介绍了生成Azure的共享访问签名与BlobService.getBlobURL()在Azure的SDK进行的Node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图生成我的本地机器上的Node.js的URL,一个blob使用 BlobService.getBlobURL()在天青库共享访问签名。但是,当我尝试通过生成的URL来检索BLOB,我得到一个验证错误,指出签名不匹配。下载从Azure管理门户同一BLOB正常工作。

下面是code我使用生成的网址:

  process.env ['AZURE_STORAG​​E_ACCOUNT'] =[MY_ACCOUNT_NAME];
process.env ['AZURE_STORAG​​E_ACCESS_KEY'] =[MY_ACCESS_KEY];VAR蔚蓝=要求('蔚蓝');
变种斑点= azure.createBlobService();blobs.getBlobUrl('[CONTAINER_NAME],[BLOB_NAME],{AccessPolicy:{
    开始:Date.now(),
    有效期:azure.date.minutesFromNow(60)
    权限:az​​ure.Constants.BlobConstants.SharedAccessPermissions.READ
}});

此函数生成的网址是:

 的https:// [MY_ACCOUNT_NAME] .blob.core.windows.net:443 / [CONTAINER_NAME] /
    [EN codeD_BLOB_NAME]
    ?ST = 2013-10-28T18%3A34%3A23Z
    &安培; SE = 2013-10-28T19%3A34%3A23Z
    &安培; SP = R
    &安培; SR = B
    &安培; SV = 2012-02-12
    &安培; SIG = RLB%2FEOAWzijkkWcseju8TJLAxzeE5e3Pvq1i68i5Erc%3D

当我尝试这个URL粘贴到浏览器中,我得到了以下错误消息:

 <错误>
    < code基AuthenticationFailed< / code>
    <消息>
        服务器无法验证请求。确保授权头的值是正确形成,包括签名。请求ID:9fe3d3ed-97f4-43d1-8c65-c95ce6b15a08时间:2013-10-28T18:34:43.3015398Z
    < /信息>
    < AuthenticationErrorDetail>
    签名不匹配。串签使用为r 2013-10-28T18:34:23Z 2013-10-28T19:34:23Z / [MY_ACCOUNT_NAME] / [CONTAINER_NAME] / [BLOB_NAME] 2012-02-12
    < / AuthenticationErrorDetail>
< /错误>

然后我试图登录到Azure管理门户,选择相同的斑点,并下载。这个工作。从管理门户提供的网址是:

 的http:// [MY_ACCOUNT_NAME] .blob.core.windows.net / [CONTAINER_NAME] /
    [EN codeD_BLOB_NAME]
    ?SV = 2012-02-12
    &安培; ST = 2013-10-28T18%3A35%3A16Z
    &安培; SE = 2013-10-28T18%3A42%3A16Z
    &安培; SR = B
    &安培; SP = R
    &安培; SIG = kcjV%2BkrNAaWOj%2F7NFwmHefXJEiEyu61U7mUTsw3pw7w%3D


解决方案

看来,作为在Azure的Node.js库版本0.7.16,有引起这种行为的错误。当BLOB名称包含空格, BlobService.getBlobURL()无法生成正确的签名。要解决,上传新的blob没有在其名称中的任何空间,并用新的blob的名字再次调用 BlobService.getBlobURL()。产生这个时候的网址将是有效的。您可以检查这个在Github 问题。

I am attempting to generate a url to a blob with a Shared Access Signature using BlobService.getBlobURL() in the Azure library on Node.js on my local machine. But when I try to retrieve the blob via the generated URL, I'm getting an Authentication Error saying that the "Signature did not match". Downloading the same blob from the Azure Management Portal works fine.

Below is the code I'm using to generate the URL:

process.env['AZURE_STORAGE_ACCOUNT'] = "[MY_ACCOUNT_NAME]";
process.env['AZURE_STORAGE_ACCESS_KEY'] = "[MY_ACCESS_KEY]";

var azure = require('azure');
var blobs = azure.createBlobService();

blobs.getBlobUrl('[CONTAINER_NAME]', "[BLOB_NAME]",  { AccessPolicy: {
    Start: Date.now(),
    Expiry: azure.date.minutesFromNow(60),
    Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.READ
}});

The URL generated by this function is:

https://[MY_ACCOUNT_NAME].blob.core.windows.net:443/[CONTAINER_NAME]/
    [ENCODED_BLOB_NAME]
    ?st=2013-10-28T18%3A34%3A23Z
    &se=2013-10-28T19%3A34%3A23Z
    &sp=r
    &sr=b
    &sv=2012-02-12
    &sig=rLB%2FEOAWzijkkWcseju8TJLAxzeE5e3Pvq1i68i5Erc%3D

When I try to paste this URL into a browser, I get the following error message:

<Error>
    <Code>AuthenticationFailed</Code>
    <Message>
        Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:9fe3d3ed-97f4-43d1-8c65-c95ce6b15a08 Time:2013-10-28T18:34:43.3015398Z
    </Message>
    <AuthenticationErrorDetail>
    Signature did not match. String to sign used was r 2013-10-28T18:34:23Z 2013-10-28T19:34:23Z /[MY_ACCOUNT_NAME]/[CONTAINER_NAME]/[BLOB_NAME] 2012-02-12
    </AuthenticationErrorDetail>
</Error>

Then I tried logging on to the Azure Management Portal, selecting the same blob, and downloading it. This worked. URL provided from the Management Portal was:

http://[MY_ACCOUNT_NAME].blob.core.windows.net/[CONTAINER_NAME]/
    [ENCODED_BLOB_NAME]
    ?sv=2012-02-12
    &st=2013-10-28T18%3A35%3A16Z
    &se=2013-10-28T18%3A42%3A16Z
    &sr=b
    &sp=r
    &sig=kcjV%2BkrNAaWOj%2F7NFwmHefXJEiEyu61U7mUTsw3pw7w%3D

解决方案

It appears that as of the Azure Node.js Library version 0.7.16, there is a bug causing this behavior. When a Blob name includes spaces, BlobService.getBlobURL() fails to generate a correct signature. To resolve, upload a new blob without any spaces in its name, and call BlobService.getBlobURL() again with the name of the new blob. The URL produced this time will be valid. You can check in on this issue on Github.

这篇关于生成Azure的共享访问签名与BlobService.getBlobURL()在Azure的SDK进行的Node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆