I'm trying to upload a file through curl --upload-file For some reason, curl freezes and upload.backup get created empty. Any ideas how this code should be changed to make it work? I must be misunderstanding the APIs
var http = require('http');
var fs = require('fs');
var server = http.createServer(function(request, response) {
var fileBackup = fs.createWriteStream("upload.backup");
var fileBytes = request.headers['content-length'];
var uploadedBytes = 0;
request.on('readable', function() {
var chunk = null;
while (null !== (chunk = request.read())) {
uploadedBytes += chunk.length;
var progress = uploadedBytes / fileBytes * 100;
response.write("progress: " + parseInt(progress, 10) + "%\n");
}
});
request.pipe(fileBackup);
}).listen(8080);