title: Why is request.file always undefined when using Multer?
body: <p>When I use Multer for NodeJS to receive files through HTTP, the req.file object is undefined. I can see the files ending up in the correct folder, but with gibberish names. Not sure if it's relevant, but I'm using Apache2 with Ubuntu.</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var fs = require('fs');
  
  var multer = require('multer');
  var upload = multer({ dest: 'uploads/' })
  var bodyParser = require('body-parser');
  
  app.use(express.static('public'));
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(multer({dest: '/var/www/185.86.150.191/uploads'}).any());
  
  app.get('/index.html', function (req, res) {
     res.sendFile( __dirname + "/" + "index.html" );
  })
  
  app.post('/file_upload', upload.single('file'), function (req, res) {
     console.log(req.baseURL)
     console.log(req.path)
     console.log(req.file.name);
     console.log(req.file.path);
     console.log(req.file.type);
     var file = __dirname + "/" + req.file.name;
  
     fs.readFile( req.file.file.path, function (err, data) {
        fs.writeFile(file, data, function (err) {
           if( err ) {
              console.log( err );
              } else {
                 response = {
                    message:'File uploaded successfully',
                    filename:req.file.file.name
                 };
              }
  
           console.log( response );
           res.end( JSON.stringify( response ) );
        });
     });    
  })
  </code></pre>
  
  <p>The entire object is not undefined. I can access req.path without any issues, however the application crashes when it reaches req.file.name, because req.file is undefined.</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'name' of undefined
        at /home/asgeir/nodejs/first_test_app/server.js:20:24
        at Layer.handle [as handle_request] (/home/asgeir/nodejs/first_test_app/node_modules/express/lib/router/layer.js:95:5)
        at next (/home/asgeir/nodejs/first_test_app/node_modules/express/lib/router/route.js:137:13)
        at Immediate. (/home/asgeir/nodejs/first_test_app/node_modules/multer/lib/make-middleware.js:53:37)
        at Immediate.immediate._onImmediate (timers.js:440:18)
        at processImmediate [as _immediateCallback] (timers.js:383:17)</p>
  </blockquote>
  
  <p>One fix I found was to make the destination path absolute, but it has not helped. The req.file object is still undefined.</p>
  
  <p>The client side looks like this: </p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;
        &lt;title&gt;File Upload Testing&lt;/title&gt;
     &lt;/head&gt;
  
     &lt;body&gt;
        &lt;h3&gt;File Upload:&lt;/h3&gt;
        Select a file to upload: &lt;br /&gt;
  
        &lt;form action = "http://185.86.150.191/node/file_upload" method = "POST" 
           enctype = "multipart/form-data"&gt;
           &lt;input type="file" name="file" size="50" /&gt;
           &lt;br /&gt;
           &lt;input type = "submit" value = "Upload File" /&gt;
        &lt;/form&gt;
  
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>