title: Simple file upload to S3 using aws-sdk and Node/Express
body: <p>I am at a loss of what I am doing wrong, here is what I have:</p>
  
  <p><em>HTML</em></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;form method="POST" action="/upload" enctype="multipart/form-data"&gt;
          &lt;div class="field"&gt;
              &lt;label for="image"&gt;Image Upload&lt;/label&gt;
              &lt;input type="file" name="image" id="image"&gt;
          &lt;/div&gt;
          &lt;input type="submit" class="btn" value="Save"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><code>Port</code> 5000 is my <em>Node.js</em> server's port.</p>
  
  <p>In this example I am using <code>POST</code> to <code>/upload</code>, and it works fine.</p>
  
  <pre><code>module.exports = function(app, models) {
  
      var fs = require('fs');
      var AWS = require('aws-sdk');
      var accessKeyId =  process.env.AWS_ACCESS_KEY || "xxxxxx";
      var secretAccessKey = process.env.AWS_SECRET_KEY || "+xxxxxx+B+xxxxxxx";
  
      AWS.config.update({
          accessKeyId: accessKeyId,
          secretAccessKey: secretAccessKey
      });
  
      var s3 = new AWS.S3();
  
      app.post('/upload', function(req, res){
  
          var params = {
              Bucket: 'makersquest',
              Key: 'myKey1234.png',
              Body: "Hello"
          };
  
          s3.putObject(params, function (perr, pres) {
              if (perr) {
                  console.log("Error uploading data: ", perr);
              } else {
                  console.log("Successfully uploaded data to myBucket/myKey");
              }
          });
      });
  
  }
  </code></pre>
  
  <p>Now I want to post the file that I am <code>POST</code>ing, which is where the problem arises.</p>
  
  <pre><code>module.exports = function(app, models) {
  
      var fs = require('fs');
      var AWS = require('aws-sdk');
      var accessKeyId =  process.env.AWS_ACCESS_KEY || "xxxxxx";
      var secretAccessKey = process.env.AWS_SECRET_KEY || "+xxxxxx+B+xxxxxxx";
  
      AWS.config.update({
          accessKeyId: accessKeyId,
          secretAccessKey: secretAccessKey
      });
  
      var s3 = new AWS.S3();
  
      app.post('/upload', function(req, res){
          var path = req.files.image.path;
          fs.readFile(path, function(err, file_buffer){
              var params = {
                  Bucket: 'makersquest',
                  Key: 'myKey1234.png',
                  Body: file_buffer
              };
  
              s3.putObject(params, function (perr, pres) {
                  if (perr) {
                      console.log("Error uploading data: ", perr);
                  } else {
                      console.log("Successfully uploaded data to myBucket/myKey");
                  }
              });
          });
      });
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'path' of undefined</p>
  </blockquote>
  
  <p>As a matter of fact <code>files</code> is completely empty.</p>
  
  <p>I am assuming I am missing something pretty obvious but I can't seem to find it.</p>