简体   繁体   English

Node.js 使用 azure 读取 blob 并创建 SAS 令牌

[英]Node.js reading a blob with azure and creating a SAS token

So I am currently writing some code that gets a container and then selects a blob and makes a SAS token.所以我目前正在编写一些代码来获取一个容器,然后选择一个 blob 并制作一个 SAS 令牌。 which all currently work but I get a error when I try to open the link.目前所有这些都有效,但是当我尝试打开链接时出现错误。

The error being given is this.给出的错误是这样的。

AuthenticationFailed Server failed to authenticate the request. AuthenticationFailed服务器未能对请求进行身份验证。 Make sure the value of Authorization header is formed correctly including the signature. 确保 Authorization header 的值格式正确,包括签名。 RequestId:somethingsomething The specified signed resource is not allowed for the this resource level RequestId:somethingsomething 此资源级别不允许指定的已签名资源

 const test = () => { const keyCredit = new StorageSharedKeyCredential('storageaccount', 'key') const sasOptions = { containerName: 'compliance', blobName: 'swo_compliance.csv', }; sasOptions.expiresOn = new Date(new Date().valueOf() + 3600 * 1000); sasOptions.permissions = BlobSASPermissions.parse("r"); const sasToken = generateBlobSASQueryParameters(sasOptions, keyCredit).toString(); console.log(`SAS token for blob container is: url/?${sasToken}`); return `url/?${sasToken}`; }

I tried to reproduce the scenario in my system able to download the blob using the sas token我试图在我的系统中重现该场景,能够使用 sas 令牌下载 blob

While you returning the return url/?${sasToken};当您返回return url/?${sasToken}; in your code remove the “/” just give the the return url?${sasToken};在您的代码中删除“/” ,只需return url?${sasToken};

Example URL: https://StorageName.blob.core.windows.net/test/test.txt?SASToken示例 URL: https://StorageName.blob.core.windows.net/test/test.txt?SASToken

I tried in my system able to download blob我尝试在我的系统中下载 blob

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM