2012-02-17 64 views
1

我想直接向客户端发送Windows Azure Blob(图像);我正在尝试:如何使用Node.js将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); 
    } 
}); 

我想将Blob流直接传递给响应流;这应该工作吗?在Firefox中,我收到一条消息:“图像无法显示,因为它包含错误”。看着萤火虫,图像的大小为0

+1

可能是一个愚蠢的问题,但为什么你想通过自己的托管服务流blob?为什么不只是将blob URL返回给客户端,或者将它们重定向到BLOB URL,并让它们通过执行HTTP GET来自行流式传输。这将为您节省缓冲/重新流式传输的托管成本。对于大量的blob数据,这可以为您节省大量资金。 – 2012-02-17 19:45:16

+0

好点,迈克,但我期望汤姆正在尝试。 – 2012-03-07 14:20:19

+0

是的,这个想法是转换blob(一个图像),然后再将其传输回客户端(即重新调整大小)。谢谢理查! – tomconte 2012-03-19 13:25:25

回答

3

这似乎prefectly为我工作(如果这是任何帮助吗?):

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将具有前导斜杠(/)。我猜的是不符合你的图像文件名。

相关问题