Skip to content

Instantly share code, notes, and snippets.

@rhalff
Created May 24, 2013 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhalff/5643010 to your computer and use it in GitHub Desktop.
Save rhalff/5643010 to your computer and use it in GitHub Desktop.
/*
* Handle file upload
*/
exports.upload = function(req, res){
// req.body is the raw image buffer.
// or maybe even req is the image buffer, dunno
console.log('upload');
console.log(res.body);
var body,
dataHandler = function(chunk) {
body += chunk;
//console.log("chunk", chunk);
};
req.on('data',dataHandler);
req.once('end',function(){
req.removeListener('data',dataHandler);
// now you have the entire request body in var body :)
//console.log(body);
//
var params = body.split('&') ;
for ( param in params ){
var pair = params[param].split('=') ;
//response.write("Name: " + pair[0] + " = " + pair[1] + "\n") ;
console.log("Name: " + pair[0]);
}
res.end() ;
});
console.log('type of body:', typeof body);
/*
req.headers['x-file-name'] // image.jpg
req.headers['x-file-size'] // 130312
req.headers['content-length'] // 130312
req.headers['content-type'] // application/x-www-from-urlencoded
req.headers['x-file-type'] // image/jpeg
*/
// hmz, maar waar is de content.
res.send({ success: true});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment