Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created November 6, 2011 11:05
Show Gist options
  • Select an option

  • Save mizzy/1342752 to your computer and use it in GitHub Desktop.

Select an option

Save mizzy/1342752 to your computer and use it in GitHub Desktop.
var formidable = require('formidable');
var http = require('http');
var sys = require('sys');
http.createServer(function(req, res) {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
var form = new formidable.IncomingForm();
form.parse(req, function(error, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(sys.inspect({fields: fields, files: files}));
console.log('completed');
}).pause();
var options = {
host: 'mizzy.org',
port: 80,
path: '/',
method: 'GET',
};
var api_req = http.request(options, function(api_res) {
api_res.on('data', function() {
console.log('api request data recieved');
});
api_res.on('end', function () {
console.log('api request end');
form.resume();
});
});
api_req.end();
return;
}
res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
}).listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment