when user sends multi part form files/images selected, in meteor or node.js, server side post url handler uses this.request or req or request object detect whether post method or other , headers etc don't understand is, file located @ request object , how retrieve can used image/file upload or manipulations @ server?
node provides querystring api parse strings like:
foo=bar&baz=qux&baz=quux&corge
...which how multi part form data sent. parsing api return object:
{ foo: 'bar', baz: ['qux', 'quux'], corge: '' }
so, can first detect method of request, , if post
, can attach handler 'data'
, data own variable, , on 'end'
, parse using querystring
:
var qs = require('querystring'); // request callback function like: function (request,response){ if(request.method=='post'){ var body = ''; request.on('data',function(data){ body += data; //reject requests have sent data (eg 2mb): if(body.length > 2e6){ // send http status code `request entity large`: response.writehead(413); response.end(); }); request.on('end', function(){ var form = qs.parse(body); //use form object }); } // end if } // end handler
Comments
Post a Comment