Skip to content

Instantly share code, notes, and snippets.

@linyows
Created November 7, 2011 02:29
Show Gist options
  • Save linyows/1344068 to your computer and use it in GitHub Desktop.
Save linyows/1344068 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.write(sys.inspect({fields: fields, files: files}) + '\n\n');
res.write('get:\n\n');
res.write(html);
res.end();
console.log('completed');
}).pause();
var options = {
host: 'mizzy.org',
port: 80,
path: '/',
method: 'GET',
};
var html = '';
var api_req = http.request(options, function(api_res) {
api_res.on('data', function(chunk) {
html+=chunk;
});
api_res.on('end', function () {
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(3011);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment