19
rated 0 times
[
20]
[
1]
/ answers: 1 / hits: 20306
/ 11 Years ago, wed, september 25, 2013, 12:00:00
I have found posts that are close to what I'm looking for, but I have not been able to successfully implement what I want. Here is the general flow:
- Submit photo with rest of venue data, as base64 data
- Strip data prefix if it exists, so I have just the image base64 data
var base64data = venue.image.replace(/^data:image/png;base64,|^data:image/jpeg;base64,|^data:image/jpg;base64,|^data:image/bmp;base64,/, '');
- Store Base64 data in GridFS via MongoDB (I'm using gridfstore)
- Then, I'd like to retrieve the image upon request as a raw image file via a URL.
// generic images route
server.get(version+'/images/:id', function(req, res) {
gridfstore.read( req.params.id, function(error,data) {
res.writeHead(200, {
'Content-Type': 'image/jpeg',
'Content-Length': data.buffer.length
});
res.end(data.buffer);
});
});
Basically, this method returns the Base64 bytes stored in GridFS. I have tried other methods but they don't return the raw image.
I'd like to pull up the image using URLs like this:
http://[localhost]/1/images/11dbcef0-257b-11e3-97d7-cbbea10abbcb
Here is a screenshot of the browser trace:
More From » node.js