seb
seb

Reputation: 3

Display images from gridfs with nodejs

I use a api sails and mongo for storing images, side front nodeJs I want download X images, just one image, the code is functionally :

db.open(function (){
    gfs.exist({ _id: id }, function(err, found) {
        if (err) {
            return err.negotiate(err);
        }

        if (!found) {
            return res.negotiate('No file found');
        }

        gfs.createReadStream({ _id: id }).pipe(res);
    });
});

For download x images......no ideas....

Thank you for your help

Upvotes: 0

Views: 233

Answers (1)

Shekhar Tyagi
Shekhar Tyagi

Reputation: 1674

  i am doing it by using this 



   if (fileExists(image_name) == false) { //check the file exist or not   
      var file = fs.createWriteStream( image_name);
                        http.get(url, function (response) {
                                response.pipe(file);
    })else{
    console.log('already exist.');
    }
    });

hope this helps.

Upvotes: 1

Related Questions