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

tom*_*nte 2 azure 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);
    }
});
Run Code Online (Sandbox Code Playgroud)

我试图将Blob流直接传递到响应流;这应该工作吗?在Firefox中,我收到一条消息:“由于包含错误,无法显示图像”。查看Firebug,图像大小为0。

Ric*_*ury 5

这似乎对我来说是完美的(如果有帮助吗?):

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");
Run Code Online (Sandbox Code Playgroud)

更新资料

只是想通了。req.url将以斜杠(/)开头。我猜这将与您的图片文件名不匹配。