【发布时间】:2021-07-30 11:04:33
【问题描述】:
我目前通过直接获取图片网址向用户提供图片(公共访问)。
const azure = require('azure-storage');
const blobService = azure.createBlobService();
router.route('/image').get( async (req, res, next) => {
try{
let containerName = process.env.CLOUD_PUBLIC_CONTAINER;
let category = req.query.category;
let blobName = category + '/'+ req.query.filename;
let hostName = process.env.AZURE_STORAGE_HOST || 'https://storageaxxxxxx.blob.core.windows.net/';
let url = blobName ? blobService.getUrl(containerName, blobName, null, hostName) : null;
res.json(url)
}catch(e){
console.log(e);
res.status(500).send("Internal Error");
}
})
我正在使用 https://azure.github.io/azure-storage-node/global.html 官方 nodejs 库与我在上面的云中看到的 azure blob 存储进行通信。
而且我知道您可以将您的 blob 存储“缓存”到这样的 cdn 端点:https://docs.microsoft.com/en-us/azure/cdn/cdn-create-new-endpoint
我正在努力寻找的东西,我怎样才能将 cdn 图像 url 提供给客户端而不是 blob 的直接公共 url?我在他们的 sdk 中看不到与 cdn 相关的任何内容,我想像:“ blobService.getNeartestCdnUrl(containerName, blobName, hostName, ...etc)”?
注意:我刚刚发现了这个旧的未维护包:https://github.com/bestander/deploy-azure-cdn,但它似乎只是用于部署而不是用于服务。
【问题讨论】:
标签: node.js azure-storage cdn azure-cdn