title: nodejs and express error when uploading file, "cannot read property of undefined"
body: <p>EDIT: === For clarity, I am looking to upload a file to the server, be it a picture or a bit of .txt ===</p>
  
  <p>I've looked around at other common problems similar to this but have been unable to alleviate my problem.</p>
  
  <p>The purpose is to create file upload functionality. The front end looks like this:</p>
  
  <pre><code>&lt;div class="holdingDiv"&gt;
      &lt;form action="/file-upload" name="upload" class="dropzone dz-clickable" id="dropzoneArea" enctype="multipart/form-data"&gt;
          &lt;input style="display:none" type="file" name="thumbnail[thumbs]" /&gt;                      
          &lt;button id="uploadSubmitter" class="btn btn-primary btn-large" type="submit"&gt;Finished&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have the form type and all that jazz setup.</p>
  
  <p>The server.js that handles the post request looks like this:</p>
  
  <pre><code>app.post('/file-upload', imports.upload);
  </code></pre>
  
  <p>Note that I also have the following required:</p>
  
  <pre><code>//needed for forms
  app.use(express.bodyParser()); 
  </code></pre>
  
  <p>aswell as funcionality necessary to call imports.upload exports function.</p>
  
  <p>the exports.upload function looks a like this:</p>
  
  <pre><code>exports.upload = function (req, res) {
      console.log('FIRST TEST: ' + JSON.stringify(req.files));
  
      console.log('second TEST: ' +req.files.thumbnail.thumbs.name);
      //get the file extenstion:
      //console.log('size' + req.files.thumbnail.size);
    //  console.log('test this: ' + req.files.thumbnail.name);
     // var fileExtension = JSON.stringify(req.files);
  
      //console.log('Im getting this file type: '+ fileExtension.name);
     // console.log('this: '+req.files.upload);
  
      //fs.readFile(req.files.uploadFiles.path, function (err, data) {
      //    // ...
      //    var newPath = __dirname + "/uploads/"+uploadFiles.name;
      //    fs.writeFile(newPath, data, function (err) {
      //        res.redirect("back");
      //    });
      //});
  }
  </code></pre>
  
  <p>A lot of stuff is commented out as I was trying different methods to get it to work. I can call it with JSON Stringify as a whole object, but I would like it as an object that I can dip into and get information from, for example I would like to know a files' type by splitting its name by '.':</p>
  
  <pre><code>req.files.thumbnail.thumbs.name
  </code></pre>
  
  <p>but when i try this (even JSON Stringyfied) it says it is undefined.</p>
  
  <p>THINGS I HAVE TRIED:</p>
  
  <p>Moving the whole function to app.js (there is a small login function that works using req.body, I assumed this may fix it.</p>
  
  <p>using JSON Stringyfy to get at specific parts of the object. (returns undefined)</p>
  
  <p>smashing my head against the keyboard. (returns undefined)</p>
  
  <p>changing the form enctype to several different things, however most of the answers on here state that form-data is the best enctype for file uploads.</p>
  
  <p>Any help and pointers as to why this is happening would be much appreciated!!</p>