简体   繁体   中英

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

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM