【发布时间】:2021-09-19 00:52:38
【问题描述】:
enter code here我正在尝试使用 javascript 下载存储在 azure blob 中的文件并收到此错误。
这是我的代码
function getUrlOfAttachmentFileFromBlob(new_fileurl,new_fileName) {
var fileHyperlink = '';
var blobUri = 'https://' + 'Storage_Account_Name' + '.blob.core.windows.net';
var containerName = 'trial';
var sas_token = 'sastoken' ;
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sas_token);
//.withFilter(new AzureStorage.Blob.ExponentialRetryPolicyFilter());
var downloadLink = blobService.getUrl(new_fileName, new_fileurl.replace('/'+containerName+'/',''), sas_token);
if (downloadLink != null)
{
alert("Link " + downloadLink);
downloadURI(downloadLink, new_fileName);
}
}
我没有在这里生成共享签名和 sas 令牌。我直接将 sas 令牌分配给变量。
当我尝试在浏览器中打开链接时出现此错误
AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:504f2ef5-f01e-0021-0e02-74e194000000
Time:2021-07-08T14:09:47.9951927Z</Message><AuthenticationErrorDetail>sp is mandatory. Cannot be empty</AuthenticationErrorDetail></Error>
我没有在我的代码中传递任何标题。
我在这里缺少什么?
SAS 令牌 = ?sp=r&st=2021-07-08T12:19:08Z&se=2021-07-08T20:19:08Z&spr=https&sv=2020-02-10&sr=c&
没有签名部分。
这就是我从 geturl 函数得到的结果 =
?%3Fsv=2020-02-10&ss=bfqt&srt=sco&sp=rwdlacuptfx&se=2021-07-11T12%3A30%3A23Z&st=2021-06-11T04%3A30%3A23Z&spr=https%2chttp&
我想我没有从这个函数中得到正确的 url,所以我用这个替换了那行
const downloadLink = blobUri +'/' + containerName + '/' + new_fileName + sas_token;
但仍然无法下载文件。但没有收到身份验证错误。
谢谢...
【问题讨论】:
-
您是否确保 Authorization 标头的值格式正确,包括签名?
-
@RobertHarvey - 错误详细信息中的授权标头部分有点误导:)。问题仅与 SAS 令牌有关。我已经提供了这个答案。
标签: javascript azure azure-blob-storage