I'm trying to parse incoming emails from the Sendgrid Inbound Webhook with Meteor, Picker and Body-Parser. I get the emails but when I log the request body I get an empty object. What am I missing here??
var bodyParser = require('body-parser');;
Picker.middleware( bodyParser.json() );
Picker.route('/incoming/', function(params, req, res, next) {
console.log("Body: " + JSON.stringify(req.body));
}
The problem was related to the content-type being multipart/form-data. Got it working like this:
var multiparty = require('multiparty');
var bodyParser = Npm.require('body-parser');
Picker.middleware(bodyParser.urlencoded({ extended: true }));
Picker.middleware(bodyParser.json());
Picker.route('/incoming/', function(params, req, res, next) {
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
console.log("Heureka: " + JSON.stringify(fields) + JSON.stringify(files));
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end("thanks");
});
});