Uploading video to Vimeo with nodejs

I'm trying to upload a video to vimeo with nodejs (https://developer.vimeo.com/apis/advanced/upload at step 3) . This is what I currently do:

Firstly I call the function to read the file:

var options = {
         hostname : dataObject.ticket.host,
         path : '/upload?ticket_id=' + dataObject.ticket.id,
         port : 8080,
         method: 'POST'
       }

postMovie(options);

I get these parameters from my object:

{
    "generated_in": "0.0308",
    "stat": "ok",
    "ticket": {
        "endpoint": "http://126535.cloud.vimeo.com:8080/upload?ticket_id=9d818e8bd066dfd54e53f1be2fa3f958",
        "endpoint_secure": "https://126535.cloud.vimeo.com/upload?ticket_id=9d818e8bd066dfd54e53f1be2fa3f958",
        "host": "126535.cloud.vimeo.com",
        "id": "9d818e8bd066dfd54e53f1be2fa3f958",
        "max_file_size": "26843545600"
    }
}

This function is called :

function postMovie(options){
    // This is an async file read
    fs.readFile('public/uploads/4363066343.mp4', function (err, data) {
      if (err) {

        console.log("FATAL An error occurred trying to read in the file: " + err);
        process.exit(-2);
      }
      // Make sure there's data before we post it
      if(data) {
        PostData(data,options);
      }
      else {
        console.log("No data to post");
        process.exit(-1);
      }
    });
};

When the file is read:

function PostData(data,options) {

      var headers = {
          'Content-Type': 'video/mp4',
          'Content-Length': data.length
      }

      options.headers = headers

      console.log(options)

  // Set up the request
  var post_req = http.request(options, function(res) {
      res.on('data', function (chunk) {
          console.log('Response: ' + chunk);
      });
  });

  // post the data
  post_req.write(data);
  post_req.end();

  post_req.on('error', function(e) {
      console.log('problem with request: ' + e.message);
  });
}

My post_req.on(error) logs this:

problem with request: write EPIPE
problem with request: write EPIPE

I understand this is because of a time-out at the serverside.

I assume my request is not well formed.

Can someone point out what I did wrong ?

The upload operation will be much simpler with the request module.

var inspect = require('eyespect').inspector();
var request = require('request')
var path = require('path')
var fs = require('fs')
var filePath = path.join(__dirname, '../public/uploads/foo.mp4')
fs.stat(filePath, function(err, stats) {
  if (err) {
    inspect(err, 'error stating file')
    return
  }
  var fileSize = stats.size
  var url = 'https://126535.cloud.vimeo.com/upload?ticket_id=9d818e8bd066dfd54e53f1be2fa3f958'
  var opts = {
    url: url,
    method: 'post',
    headers: {
      'Content-Length': fileSize,
      'Content-Type': 'foo'
  }
  var r = request(opts)

  // pipe the file on disk to vimeo
  var readStream = fs.createReadStream(filePath)
  readStream.pipe(r)
  readStream.on('error', function (err) {
    inspect(err, 'error uploading file')
  })
  readStream.on('end', function (err) {
    inspect('file uploaded correctly')
  })
})

Request also allows you to set the timeout option as well if the file is big and thus takes a long time to upload