title: Use NodeJS to upload file in an API call
body: <p>I'm looking at using NodeJS to act as the server to build an API.</p>
  
  <p>Ideally I'd love for there to be an API endpoint to send a set of information as well as a file which can be saved to the files system.</p>
  
  <p>Most examples I've seen are for sending a file via a form, however I'd like to do this through a post request.</p>
  
  <p>Does anyone know how I could achieve this (if it's at all possible)?</p>
  
  <p>At the moment what I'd like to achieve is something along the following lines:</p>
  
  <pre><code>app.post('/Some/Endpoint/', controller.handleSomeEndpoint, function(request, response) {
      response.send('Finished Request');
  });
  
  exports.handleSomeEndpoint = function(request, response, next) {
      var bodyarr = []
      request.on('data', function(chunk){
        bodyarr.push(chunk);
      })
      request.on('end', function(){
        console.log( bodyarr.join('') );
      })
  }
  </code></pre>
  
  <p>But the data and end never get called if I run a curl command along the lines of:</p>
  
  <pre><code>curl http://127.0.0.1:5000/Some/Endpoint/ -F 'test=@test_file'
  </code></pre>
  
  <p>Cheers,
  Matt</p>