nodejs display image stored in gridFS to html

前端 未结 3 1347
醉酒成梦
醉酒成梦 2021-01-16 07:29

Hi I\'m new to nodejs and gridFS I\'m trying to display images stored in gridFS to my html page

Currently, I am using this code.

gfs.exist(options, f         


        
3条回答
  •  不知归路
    2021-01-16 08:06

    Try the function like below,

    function(req,res){
      gfs.files.findOne({ filename: req.params.filename }, (err, file) => {
        res.contentType(file.contentType);
        // Check if image
        if (file) {
          // Read output to browser
          const readstream = gfs.createReadStream(file.filename);
          readstream.pipe(res);
        } else {
            console.log(err);
        }
      });
    };
    

提交回复
热议问题