typescript - 如何从 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?
解决方案
我猜你得到的 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 令牌。
推荐阅读
- java - 如何通过 setText 方法设置定时器?
- spring-security - 带有华夫饼的 LDAP SSO
- css - 如何使用 css 网格做与此类似的事情?
- git - 撤消本地文件更改的不同命令
- geojson - Turf - 获取 geojson 的所有特征,这些特征在一个点的范围内
- database - 如何在 dynamoDB、嵌套字典或多个项目中构造数据?
- oracle - 从 Oracle 中的标准输入复制
- android - Android上的libvlc“图片来不及显示”错误
- c# - 在 C# 程序中使用“Microsoft.Office.Interop.Word”时,语法检查不适用于感叹句
- javascript - js:在文档中的所有 div 上进行 for 循环,以在每个 div 中添加一个新的 div —— for 循环包括新添加的 div