Display Image in GridFS

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 output. When i append this data to <img src="data:image/jpeg;base64,(data)">, the image doesn't show.

// create a read stream from gfs...
.createReadStream({ filename: 'error1.png' })
// and pipe it to Express' response

Output res :- enter image description here

Edited :-

I tried this :-

img.src = 'data:image/jpeg;base64,' + btoa(res);

Output rendered is :-

<img src="data:image/jpeg;base64,W29iamVjdCBPYmplY3Rd">

No image shown.



I use file stream demonstrate:

var rstream = fs.createReadStream('test.png');

var bufs = [];

rstream.on('data', function(chunk) {


}).on('end', function() { // done

    var fbuf = Buffer.concat(bufs);

    var base64 = (fbuf.toString('base64'));

    res.send('<img src="data:image/jpeg;base64,' + base64 + '">');


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.