2

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);

            });
}
Mariya James
  • 935
  • 2
  • 9
  • 27
  • Sorry, this is not possible(hopefully yet). gridfs is still so basic that you cant even query by meta tag or any field other than _id. – Rob May 20 '15 at 23:39
  • Thanks Rob. But do you think by sending a http request for each image makes the site performance slow?Also do you think its a conventional method to do the same? – Mariya James May 21 '15 at 10:30
  • not really, at the end of the day your still moving the same amount of data. If you have a lot of images, you can set you html `src` to the file get for each id and then use a lazy loader so that the page only calls the images that are in the view port. – Rob May 21 '15 at 13:47

0 Answers0