I think Node.js v0.12.0 has a bug, before I submit a ticket I wanted to see if anyone else had any ideas. The stripped down request below succeeds but causes the next request to time out.
var reader = fs.createReadStream('file.pdf', {bufferSize: 64 * 1024});
var req = https.request(common.options, function(res) {
res.setEncoding('utf8');
var errors, chunks;
res.on('data', function (chunk) {
chunks = JSON.parse(chunk);
errors = chunk.errors;
});
res.on('end', function(){
if (callback){return callback(errors, chunks);}
})
});
req.on('error', function(e) {
if (callback){
return callback(e.message);
}
});
req.write(file);
//pipe the file and append a closing line
reader.pipe(req, { end: false });
reader.on('end', function() {
reader.unpipe(req);
req.end(closingLine);
});