I have a nodejs app that uses Mongo and GridFS to store images. I'm trying to display these images to the browser via Node.js (using express framework).
I'm currently using:
res.writeHead(200, {'Content-Type': 'image/jpeg' });
res.end(imageStore.currentChunk.data.buffer, 'binary');
imageStore is a the gridStore object after creating a new GridStore and calling gridStore.open(...)
var gridStore = new GridStore(self.collection.db, doc._id, doc.filename, 'r', {
chunk_size: doc.chunkSize
});
gridStore.open(callback);
I'm sure this isn't the right way, it displays a broken image. Any suggestions?
Thanks!
Edit:
After updating to mongodb native 1.0.2, I'm trying to stream the data by using:
res.contentType("image/jpeg");
var imageStream = imageStore.stream(true);
imageStream.pipe(res);
imageStore is the object after using gridStore.open(function(err, imageStore){ })