我正在尝试使用本地计算机上Node.js上的Azure库中的BlobService.getBlobURL()
生成具有共享访问签名的blob的URL。但是当我尝试通过生成的URL检索blob时,我收到一条身份验证错误,指出“签名不匹配”。从Azure管理门户下载相同的blob可以正常工作。
以下是我用来生成网址的代码:
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
}});
此功能生成的URL为:
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
当我尝试将此网址粘贴到浏览器中时,收到以下错误消息:
<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>
然后我尝试登录Azure管理门户,选择相同的blob并下载它。这很有效。管理门户提供的URL是:
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
答案 0 :(得分:2)
从Azure Node.js Library版本0.7.16开始,出现了导致此行为的错误。当Blob名称包含空格时,BlobService.getBlobURL()
无法生成正确的签名。要解析,请上传名称中没有任何空格的新blob,然后使用新blob的名称再次调用BlobService.getBlobURL()
。此次生成的URL将有效。您可以登录issue on Github。