首页 > 解决方案 > 如何从 blob URL 查看/下载私有 blob?

问题描述

我有 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

标签: typescriptazureauthorizationazure-blob-storage

解决方案


我猜你得到的 SAS 令牌是错误的。您可以尝试在Azure 门户中生成 SAS 令牌(导航到您的 blob -> 生成 SAS),然后使用GET https://<storage-name>.blob.core.windows.net/<container-name>/myblob.txt?<sas-token>.

在此处输入图像描述

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();

AnonymousCredential您可以使用typecipt sample测试您的 SAS 令牌。


推荐阅读