Last active
December 23, 2015 23:09
-
-
Save remotevision/6708240 to your computer and use it in GitHub Desktop.
Base64 image in GridFS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////// | |
// Doesn't work in browser | |
// expecting image to be displayed (no html) | |
//////////////////////////// | |
// generic images route | |
server.get(version+'/images/:id', function(req, res) { | |
gridfstore.read( req.params.id, function(error,data) { | |
var img = new Buffer(data.buffer, 'base64'); | |
res.writeHead(200, { | |
'Content-Length': img.length, | |
'Content-Type': 'image/jpeg' | |
}); | |
res.write(img); | |
res.end(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////// | |
// works in browser | |
// image is displayed using html <img src="..."> | |
//////////////////////////// | |
// generic images route | |
server.get(version+'/images/:id', function(req, res) { | |
gridfstore.read( req.params.id, function(error,data) { | |
var img = new Buffer(data.buffer, 'base64'); | |
res.end("<html><body><img src=\"" + img + "\"/></body></html>"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment