【发布时间】:2015-03-27 23:43:15
【问题描述】:
我有一个 nodejs 应用程序作为 Azure 云服务中的工作角色运行,我有两个 blob 存储容器,应用程序在响应某些用户请求时将从这些容器中读取。
这是我的设置:
使用 azure-storage 包与我的 blob 存储接口。
两个容器,每个容器都保存用户在某个时候可能会要求的不同类型的文件。
我使用以下代码将文件流式传输到 HTTP 响应:
exports.getBlobToStream = function(containerName, fileName, res) {
var blobService = azure.createBlobService();
blobService.getBlobProperties(containerName, fileName, function(error, properties, status){
if(error || !status.isSuccessful)
{
res.header('Content-Type', "text/plain");
res.status(404).send("File " + fileName + " not found");
}
else
{
res.header('Content-Type', properties.contentType);
res.header('Content-Disposition', 'attachment; filename=' + fileName);
blobService.createReadStream(containerName, fileName).pipe(res);
}
});
};
一个重要的
在过去,我从任一容器读取都没有问题。在我对这个问题的研究中,我在https://github.com/Azure/azure-sdk-for-node/issues/434 的包罗万象的 azure-sdk-for-node 上发现了一个相同(但已过时)的问题。解决该问题的解决方案也解决了我的问题,但我不明白为什么。特别是当我可以从同一个应用程序中的另一个容器中读取并使用相同的代码而没有任何问题时。
我可以接受解决方案,但想了解发生了什么。有什么想法或建议吗?
【问题讨论】:
标签: node.js azure azure-storage