如何通过node.js中的@azure/storage-blob获取blob存储中文件的安全url?

2024-04-22

我正在使用 @azure/storage-blob,我可以上传文件,但如何检索它?有什么想法如何获取存储的 SAS url?

我需要生成几分钟后过期的 url,并且 url 是基于令牌的,因为容器不供公共访问。请在 node.js 中提供帮助或指导我使用一些插件,该插件有助于获取/生成 blob 存储中该文件的 sas url。先感谢您!


要在 blob 上生成共享访问签名 (SAS URL),您可以使用generateBlobSASQueryParameters https://learn.microsoft.com/en-us/javascript/api/@azure/storage-blob/?view=azure-node-latest#generateBlobSASQueryParameters_BlobSASSignatureValues__StorageSharedKeyCredential_SDK 中提供的功能。

const blobSAS = generateBlobSASQueryParameters({
    containerName, // Required
    blobName, // Required
    permissions: BlobSASPermissions.parse("r"), // Required
    startsOn: new Date(), // Required
    expiresOn: new Date(new Date().valueOf() + 86400) // Optional. Date type
   },
  sharedKeyCredential // StorageSharedKeyCredential - `new StorageSharedKeyCredential(account, accountKey)`
).toString();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过node.js中的@azure/storage-blob获取blob存储中文件的安全url? 的相关文章

随机推荐