title: Cannot read property 'path' of undefined nodejs
body: <p>Here is my server side code:</p>
  
  <pre><code>var fs = require('fs'),
  MongoClient = require('mongodb').MongoClient, db;
  var url = "mongodb://localhost:27017/fullwardrobedb";
  MongoClient.connect(url, {native_parser: true}, function (err, connection) {
  if (err) {
      console.log("Cannot connect to database " + url);
      process.exit(1);
  }
  db = connection;
  });
  
  fs.exists(__dirname + '/uploads', function(exists){
  if(!exists){
      console.log('Creating dir ' + __dirname + '/uploads');
      fs.mkdir(__dirname + '/uploads', function(err){
          if(err){
              console.log('Error creating dir');
              process.exit(1);
          }
      })
  }
  });
  
  exports.addPhoto = function(req,res,next){
  console.log('Starting upload file');
  console.log(req.files);
  console.log(req.files.file);
  var file = req.files.file,
      filePath = req.files.file.path,
      lastIndex = filePath.lastIndexOf("/"),
      tmpFileName = filePath.substr(lastIndex + 1),
      image = req.body,
      images = db.collection('images');
  
  image.fileName = tmpFileName;
  console.log('New file: ' + tmpFileName);
  
  images.insert(image, function (err, result) {
      if (err) {
          console.log(err);
          return next(err);
      }
      res.json(image);
  });
  }
  </code></pre>
  
  <p>And server.js:</p>
  
  <pre><code>var express = require('express'),
      http = require('http'),
      path = require('path'),
      clothes = require('./routes/clothes'),
  users = require('./routes/users');
  photos = require('./routes/photos')
  
  var app = express();
  
  app.configure(function(){
  app.use(express.logger('dev'));
  //  app.use(express.bodyParser({
  //        uploadDir:__dirname +  '/uploads',
  //        keepExtensions: true
  //    }));
  app.use(express.json());
  app.use(express.multipart({
      uploadDir:__dirname +  '/uploads',
      keepExtensions: true
  }));
  app.use(express.static(path.join(__dirname, './uploads')));
  });
  
  app.get('/clothes', clothes.findAll);
  //app.get('/clothes/:id', clothes.findById);
  // app.post('/clothes', clothes.addWine);
  //app.put('/clothes/:id', clothes.updateWine);
  //app.delete('/clothes/:id', clothes.deleteWine);
  
  app.post('/users', users.addUser);
  app.get('/users', users.findAll);
  app.get('/users/:id', users.findById);
  app.put('/users/:id', users.updateUser);
  
  app.post('/photos', photos.addPhoto);
  
  app.listen(3000,'192.168.1.8');
  console.log('Listening on port 3000...');
  </code></pre>
  
  <p>The problem is that when I'm trying to put there curl image with command <code>curl -i -H "Content-Type:image/jpeg" -F filedata=@antoni_01.jpg http://192.168.1.8:3000/photos</code></p>
  
  <p>I' getting such exception:</p>
  
  <pre><code>Starting upload file
  {}
  undefined
  TypeError: Cannot read property 'path' of undefined
      at exports.addPhoto (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/routes/photos.js:31:34)
      at callbacks (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/lib/router/index.js:164:37)
      at param (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/lib/router/index.js:138:11)
      at pass (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/lib/router/index.js:145:5)
      at Router._dispatch (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/lib/router/index.js:173:5)
      at Object.router (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/lib/router/index.js:33:10)
      at next (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/node_modules/connect/lib/proto.js:194:15)
      at Object.staticMiddleware [as handle] (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/node_modules/connect/node_modules/serve-static/index.js:67:61)
      at next (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/node_modules/connect/lib/proto.js:194:15)
      at Object.multipart [as handle] (/Users/robert/dev/repos/fullwardrobe/fullwardrobe_nodejs/node_modules/express/node_modules/connect/lib/middleware/multipart.js:97:43)]
  </code></pre>
  
  <p>Does anyone can help me? Please note that I'm new in Node JS :)</p>