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

Osa*_*bid 0 azure-storage-blobs node.js azure-blob-storage

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

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

Gau*_*tri 5

要在 blob 上生成共享访问签名 (SAS URL),您可以使用generateBlobSASQueryParametersSDK 中提供的函数。

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();
Run Code Online (Sandbox Code Playgroud)