title: NodeJS/Express can't set headers after they are sent error when I upload files
body: <p>I am working on a small web portal, and I've run into an error when I am uploading files(images) > ~25kb. I've tested the system, and it works great with small images, but then when I try a larger image, everything breaks.</p>
  
  <p>I am using the latest version of node, express 3.4.0, multer 0.0.7 and here is the code in question:</p>
  
  <p>Server:</p>
  
  <pre><code>var express = require('express'),
      multer = require('multer'),
      api = require('./routes/api.js'),
      http = require('http'),
      path = require('path'),
      app = express(),
      server = http.createServer(app);
  
  
  app.use(express.logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded());
  app.set('port', process.env.VCAP_APP_PORT || 7000);
  app.use(multer({dest: __dirname + '/uploads/'}))
  app.use(app.router);
  
  app.configure(function()
      app.use("/uploads",express.static(__dirname + '/uploads'));
  
      app.post('/api/upload/file', api.upload);
  
      app.use(function(err, req, res, next) {
          if(!err) return next();
          console.log(err.stack);
          res.json({error: true});
      });
  
      app.use(multer({
          dest:'./uploads/',
           rename: function (fieldname, filename) {
              return filename.replace(/\W+/g, '-').toLowerCase();
          }
      }));
  });
  
  server.listen(app.get('port'), function(){
      console.log('Express server listening on port ' + app.get('port'));
  });
  </code></pre>
  
  <p>And the api.upload function:</p>
  
  <pre><code>exports.upload = function(req, res) {
  
      console.log("Upload");
      var resumeName = null,
          picName = null;
      console.log("File: " + JSON.stringify(req.files));
      if(req.files.resume.size &gt;= 0 || req.files.pic.size &gt;= 0) {
          if(req.files.resume.size &gt; 0) {
              resumeName = req.files.resume.name;
          }
          if(req.files.pic.size &gt; 0) {
              picName = req.files.pic.name;
          }
          console.log("Got file");
      }
      console.log("sending...");
      res.send({picName: picName, resumeName: resumeName});
  }
  </code></pre>
  
  <p>If it helps at all, my front end is angular, and I am using restangular and ng-upload to assist with from submitting and uploading files.</p>