I'm developing a REST HTTP API that has iOS clients connecting to it. The way it's currently set up (and tested with POSTman chrome ext) is that I make the request for the resource, and I have to wait for the whole thing to get read in and spit out for it to show up as a response.
Is this a good method for iOS and Mac client consumption or is there a better method for serving from GridFS?
I'm doing the following:
// Download a PDF
app.get('/api/download-pdf/:pdf_id', function(req, res){
var gfs = new mongodb.GridStore(mongoose.connection.db, ObjectID(req.params.pdf_id), "r");
gfs.open(function(err,gs) {
if (err){
res.send(500);
}
else{
gs.read(function(err,data) {
res.header('Content-type','application/pdf');
res.send(data);
gs.close(function(err) {});
if (err) throw(err);
});
}
});
});
the node driver now supports streaming to/from GridFS http://christiankvalheim.com/post/29753345741/new-features-in-the-driver-for-mongodb-2-2?8e43c3e0
gs.pipe(anotherStream)
See Streams