javascript - Display Image in GridFS -
i using gridfs-stream https://github.com/aheckmann/gridfs-stream & on displaying image gridfs.
when reading data gives me following output. when append data <img src="data:image/jpeg;base64,(data)">
, image doesn't show.
gfs // create read stream gfs... .createreadstream({ filename: 'error1.png' }) // , pipe express' response .pipe(res);
output res :-
edited :-
i tried :-
img.src = 'data:image/jpeg;base64,' + btoa(res);
output rendered :-
<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) { 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 + '">'); });
Comments
Post a Comment