[英]Azure storage authorization failed or format is wrong
Good day everybody, I'm stuck with authorization on azure storage. 大家好,我被授权使用Azure存储。 When I am uploading only one file(blob) I put SAS key in the url and everything works fine. 当我仅上传一个文件(blob)时,我将SAS密钥放在url中,一切正常。 But when I need to create chunks in BLOB service, there must be Authorization header(Amazon says that) when creating them. 但是,当我需要在BLOB服务中创建块时,在创建它们时必须有Authorization标头(Amazon这样说)。 I am trying to use this article to create authorization. 我正在尝试使用本文来创建授权。
There is my JavaScript code(I use ng-file-uploader library): 这是我的JavaScript代码(我使用ng-file-uploader库):
$scope.upload = function (file) {
blockId = blockId + 1;
Upload.upload({
url: "https://MYSTORAGENAME.blob.core.windows.net/kont1/"+ file.name + "?comp=block&blockid=" + blockId,
method: 'PUT',
resumeChunkSize: '40MB', // upload in chunks of specified size
headers: {
'Content-type': 'multipart/form-data',
'Authorization': 'SharedKey' + "MYSTORAGENAME:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5/H/w=",
'x-ms-version': '2015-12-11',
'x-ms-date': new Date().toUTCString()
},
data: {file: file}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
This request returns: 400 (Authentication information is not given in the correct format. Check the value of Authorization header.) 该请求返回: 400(未以正确的格式提供认证信息。检查Authorization标头的值。)
When I try to change this: 'Authorization': 'SharedKey' + "MYSTORAGENAME:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5/H/w=" 当我尝试更改此设置时: 'Authorization':'SharedKey'+“ MYSTORAGENAME:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5 / H / w =”
to this: 'Authorization': "SharedKey sand2storage:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5/H/w=" 对此: “授权”:“ SharedKey sand2storage:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5 / H / w =“
Then it returns: 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.) 然后返回: 403(服务器无法验证请求。请确保正确构成Authorization标头的值,包括签名。)
I spent 2days on this and still can't get it right, maybe somebody see's what I am missing? 我花了2天的时间,仍然无法解决问题,也许有人看到了我所缺少的? Thank you in advance. 先感谢您。
NOTE: 注意:
iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5/H/w= iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5 / H / w =
I generate this key in Azure page each try to make it sure that key is correct. 我会在Azure页面中生成此密钥,每次尝试都要确保该密钥正确。
If you're using Shared Access Signature (SAS)
, then you don't need to specify the Authorization
header as the SAS token contains this value. 如果您使用的是Shared Access Signature (SAS)
,则无需指定Authorization
标头,因为SAS令牌包含此值。 You also need not define x-ms-version
and x-ms-date
headers. 您也不需要定义x-ms-version
和x-ms-date
标头。 What you do need to include is x-ms-blob-type
request header and set its value to BlockBlob
. 您需要包括的是x-ms-blob-type
请求标头,并将其值设置为BlockBlob
。
What you would need to do is take the SAS token and append that to your URL (please make sure that you don't include the ?
in the SAS Token. 您需要做的就是获取SAS令牌,并将其附加到您的URL(请确保您在SAS令牌中未包含?
。
Assuming you're storing the Sas Token from portal in a variable called sasToken
, your code would be: 假设您将门户网站中的Sas令牌存储在名为sasToken
的变量中,则代码为:
$scope.upload = function (file) {
blockId = blockId + 1;
Upload.upload({
url: "https://MYSTORAGENAME.blob.core.windows.net/kont1/"+ file.name + "?comp=block&blockid=" + blockId + "&" + sasToken,
method: 'PUT',
resumeChunkSize: '40MB', // upload in chunks of specified size
headers: {
'Content-type': 'multipart/form-data',
'Authorization': 'SharedKey' + "MYSTORAGENAME:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5/H/w=",
'x-ms-version': '2015-12-11',
'x-ms-date': new Date().toUTCString()
},
data: {file: file}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.