【发布时间】:2021-10-28 20:45:11
【问题描述】:
已解决,原来是浏览器缓存
我正在尝试从 Azure Blob 存储中获取图像,由于某种原因,ExpireOn 无法正常工作,我可以正常访问该图像,但在过期时间过后它不会使链接失效。
import { BlobSASPermissions, generateBlobSASQueryParameters, StorageSharedKeyCredential} from "@azure/storage-blob";
export async function BlobService2(){
const accountName = process.env.ACCOUNT_NAME;
const containerName = process.env.CONTAINER_NAME;
const blobName = process.env.BLOB_NAME;
const accountKey = process.env.ACCOUNT_KEY;
const SharedKeyCredential = new StorageSharedKeyCredential(accountName , accountKey)
const blobSAS = generateBlobSASQueryParameters({
containerName, // Required
blobName, // Required
permissions: BlobSASPermissions.parse("r"),
startsOn: new Date(), // Required
expiresOn: new Date(new Date().getTime() + 5*60000)
},SharedKeyCredential).toString();
const URL = `https://${accountName}.blob.core.windows.net/${containerName}/${blobName}?${blobSAS}`
console.log(URL);
}
【问题讨论】:
-
请检查浏览器是否没有缓存数据。我经常看到这种情况发生。
-
如果您在没有 blobSAS 的情况下访问此 URL 会发生什么? curl -v https://${accountName}.blob.core.windows.net/${containerName}/${blobName} 当然用实际值替换。
-
@JohnHanley - OP 很可能会收到 404 错误(假设 blob 容器的 ACL 是私有的)。
-
@GauravMantri - 有时用户忘记管理访问控制。收集数据以确定真正的问题并获得 OP 思维的一部分。
-
JohnHanley 我收到此错误:指定的资源不存在。 @GauravMantri 是的!非常感谢,我尝试使用其他浏览器,但我得到无效链接,非常感谢!
标签: node.js typescript azure azure-storage azure-blob-storage