title: Using multer to recieve a FormData object as a node.js server
body: <p>I have an HTML form with two buttons (along with other text input areas), and I have some front end javascript code to handle the submit. On the submit, I create a FormData object and store the file in it. Then I send that through an jquery ajax request to a node.js server. However, this is where the problem is - when I try to access the file in the server, the file is always undefined - i've tried accessing it with <code>req.body, req.files, req.file</code> but its always undefined. Is this a problem with the ajax request, or the way i'm receiving it?</p>
  
  <p>upload file button: </p>
  
  <pre><code>&lt;input id="element_3" name="element_3" class="element file required" accept="application/pdf" type="file"/&gt;
  </code></pre>
  
  <p>submit button:</p>
  
  <pre><code>&lt;input id="saveForm" class="button_text" type="submit" name="submit" value="Submit"/&gt;
  </code></pre>
  
  <p>handle submit:</p>
  
  <pre><code>$('#form_1039889').submit(function(event) {
      event.preventDefault();
      event.stopImmediatePropagation();
      var file = $('#element_3').get(0).files[0];
      var fd = new FormData();
      fd.append('pdf', file);
      $.ajax({
          url: '/addPdf',
          data: fd,
          processData: false,
          contentType: false,
          type: 'POST',
          success: function(response) {
             //success TODO code
          }
      });
  });
  </code></pre>
  
  <p>relevant server code:</p>
  
  <pre><code>app.post('/addPdf', [multer({dest: "./uploads/"}).single('avatar'), function(req, res) {
      console.log("file: " + req.file);
  }]);
  </code></pre>