Display Image in GridFS

后端 未结 1 1970
别那么骄傲
别那么骄傲 2021-01-16 11:10

I am using gridfs-stream https://github.com/aheckmann/gridfs-stream & currently i am on displaying image from gridFS.

When reading data it gives me following out

相关标签:
1条回答
  • 2021-01-16 11:49

    I use file stream demonstrate:

    var rstream = fs.createReadStream('test.png');
    
    var bufs = [];
    
    rstream.on('data', function(chunk) {
    
        bufs.push(chunk);
    
    }).on('end', function() { // done
    
        var fbuf = Buffer.concat(bufs);
    
        var base64 = (fbuf.toString('base64'));
    
        res.send('<img src="data:image/jpeg;base64,' + base64 + '">');
    });
    
    0 讨论(0)
提交回复
热议问题