title: How to best serve a GridFS stored file (PDF) via my Express.js driven API to a connected client (iOS)?
body: <p>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. </p>
  
  <p>Is this a good method for iOS and Mac client consumption or is there a better method for serving from GridFS?</p>
  
  <p>I'm doing the following:</p>
  
  <pre><code>  // 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);
          });
        }
      });
    });
  </code></pre>