如何使用Node.js将Windows Azure Blobstream式传输到客户端?

我想直接发送一个Windows Azure Blob(一个图像)到客户端; 我正在尝试这个:

blobService.getBlobToStream('images', req.url, res, function(err, blob) { if (!err) { res.writeHead(200, { 'Content-Type': blob.contentType }); } else { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(err); } }); 

我正在尝试将Blobstream直接传递给响应stream; 应该这个工作吗? 在Firefox中,我收到一条消息:“图像无法显示,因为它包含错误”。 看着Firebug,图像的大小是0。

这对我来说似乎是很正常的(如果这有什么帮助的话):

 var azure = require('azure'); var http = require('http'); http.createServer(function (req, res) { var blobService = azure.createBlobService("xxx", "yyy", "blob.core.windows.net").withFilter(new azure.ExponentialRetryPolicyFilter()); blobService.getBlobToStream('container', 'image.png', res, function(error){ if(!error){ res.writeHead(200, {'Content-Type': 'image/png'}); res.end(); } else { console.log('error'); console.log(error); res.end(); } }); }).listen(8080, "127.0.0.1"); 

更新

只是想通了。 req.url将有一个前导斜杠(/)。 我猜的是不匹配你的图像文件名。