title: NodeJS FileUpload - Cannot read property Undefined
body: <p>Im using NodeJS, ExpressJS, mongoose, EJS.</p>
  
  <p>upload form:</p>
  
  <pre><code>&lt;form method='post' enctype='multipart/form-data'&gt;
      &lt;input type='text' name='photo[name]'/&gt;
      &lt;input type='file' name='photo[image]'/&gt;
      &lt;input type='submit' value='Upload'/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>model:</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  mongoose.connect('mongodb://localhost/photo_app');
  var schema = new mongoose.Schema({
      name: String,
      path: String
  });
  
  module.exports = mongoose.model('Photo', schema);   
  </code></pre>
  
  <p><code>app.js</code>:</p>
  
  <pre><code>var app = express();
  ...
  app.set('view engine', 'ejs');
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  ...
  </code></pre>
  
  <p>route:</p>
  
  <pre><code>var Photo = require('../models/Photo');
  var path = require('path');
  var fs = require('fs');
  var join = path.join;
  
  exports.submit = function (dir) {
      return function(req, res, next){
          var img = req.files.photo.image;
          var name = req.body.photo.name || img.name;
          var path = join(dir, img.name);
          fs.rename(img.path, path, function(err){
              if (err)
                  return next(err);
              Photo.create({
                  name: name,
                  path: img.name
              }, function (err) {
                  if (err)
                      return next(err);
                  res.redirect('/');
              });
          });
      };
  };
  </code></pre>
  
  <p>The problem when trying to upload:</p>
  
  <pre><code>500 TypeError: Cannot read property 'photo' of undefined
  </code></pre>