Skip to content

Instantly share code, notes, and snippets.

@outbounder
Created August 19, 2011 11:35
Show Gist options
  • Save outbounder/1156621 to your computer and use it in GitHub Desktop.
Save outbounder/1156621 to your computer and use it in GitHub Desktop.
var formidable = require("formidable");
var fs = require("fs");
var form = new formidable.IncomingForm(),
files = [],
fields = [];
form.uploadDir = __dirname+"/uploads";
form
.on('field', function(field, value) {
fields.push([field, value]);
})
.on('file', function(field, file) {
files.push([field, file]);
})
.on('end', function() {
response.writeHead(200, {'content-type': request.headers['content-type']});
response.end(fs.readFileSync(files[0][1].path));
});
form.parse(request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment