Created
November 6, 2011 11:05
-
-
Save mizzy/1342752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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