How to retrieve all images from gridFs in a single http Request

旧巷老猫 提交于 2019-12-24 03:40:00

问题


I am new in mean.js(angular.js+node.js) and using GridFs to store images. In order to retrieve the images now i am sending a http request for each image. I am worried about the fact that whether it will affect the speed of the site. So i want to retrieve all images together From gridFs. Is that possible? can anybody help me? below provided is my client side code.

 $http.get('/uploads?filename=' + imagename).success(function(response) {
$scope.img.push({imageph: response, image: item.image, url: item.url});
}).error(function (err) {
console.log('Error uploading file: ' + err);
});

my server side code is:

var qo = url.parse(req.url, true).query;
var filename = qo.filename;
if (filename !== 'undefined')
{
    var rstream = gfs.createReadStream(filename);
    var bufs = [];
    rstream.on('data', function (chunk) {
        bufs.push(chunk);
    }).on('error', function () {
        res.send();
    })
            .on('end', function () { // done

                var fbuf = Buffer.concat(bufs);

                var imageFile = (fbuf.toString('base64'));

                var ret = 'data:image/jpeg;base64,' + imageFile;
                res.send(ret);

            });
}

来源:https://stackoverflow.com/questions/30350857/how-to-retrieve-all-images-from-gridfs-in-a-single-http-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!