我有 typecipt 应用程序,它将文件上传到 Azure blob 存储(私人访问)。 现在我需要从 blob URL 在浏览器中查看文件。 我们如何从 blob URL 查看私有 blob 文件。我有与该存储帐户关联的 SAS 令牌。 但是将 SAS 令牌附加到 blob URL 不起作用。 请建议实现这一目标的方法。
网址: https://teststorage.blob.core.windows.net/container1/folder2/forest.jpg
带有 SAS 令牌的 URL: https://teststorage.blob.core.windows.net/container1/folder2/forest.jpg?
我猜您获得的 SAS 令牌是错误的。您可以尝试在 Azure Portal 中生成 SAS 令牌(导航到您的 blob -> 生成 SAS),并使用
GET https://<storage-name>.blob.core.windows.net/<container-name>/myblob.txt?<sas-token>
获取 blob。
generateBlobSASQueryParameters
生成容器 SAS 令牌的示例代码。如果您想要 blob SAS,请将 blobName 添加到参数中。
var storage = require("@azure/storage-blob")
// Use StorageSharedKeyCredential with storage account and account key
const sharedKeyCredential = new storage.StorageSharedKeyCredential(account, accountKey);
var expiryDate = new Date();
startDate.setTime(startDate.getTime() - 5*60*1000);
expiryDate.setTime(expiryDate.getTime() + 24*60*60*1000);
const containerSAS = storage.generateBlobSASQueryParameters({
expiresOn : expiryDate,
permissions: storage.ContainerSASPermissions.parse("rwl"),
protocol: storage.SASProtocol.Https,
containerName: containerName,
startsOn: startDate,
version:"2018-03-28"
}, sharedKeyCredential).toString();
您可以在
typescipt 示例中使用
AnonymousCredential
测试您的 SAS 令牌。