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.

```
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 ) );
      });
   });    
})

```

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.

> 
> 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)
> 
> 
> 

One fix I found was to make the destination path absolute, but it has not helped. The req.file object is still undefined.

The client side looks like this: 

```
<html>
   <head>
      <title>File Upload Testing</title>
   </head>

   <body>
      <h3>File Upload:</h3>
      Select a file to upload: <br />

      <form action = "http://185.86.150.191/node/file_upload" method = "POST" 
         enctype = "multipart/form-data">
         <input type="file" name="file" size="50" />
         <br />
         <input type = "submit" value = "Upload File" />
      </form>

   </body>
</html>

```