Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Meteor中使用IronRouter解析URL编码的消息_Meteor_Email - Fatal编程技术网

在Meteor中使用IronRouter解析URL编码的消息

在Meteor中使用IronRouter解析URL编码的消息,meteor,email,Meteor,Email,我正在使用解析电子邮件到我(未来)的Meteor应用程序。因此,我使用Iron Router创建了一个webhook,它应该处理消息和附件 使用以下代码,在控制台中编写{} Router.route('/receive/', {where: 'server'}) .post(function(req, res) { console.log(this.request.body); }); 我发现一些人报告了类似的问题,但提供的解决方案不适合我 有什么想法吗 在链接中描述了

我正在使用解析电子邮件到我(未来)的Meteor应用程序。因此,我使用Iron Router创建了一个webhook,它应该处理消息和附件

使用以下代码,在控制台中编写
{}

  Router.route('/receive/', {where: 'server'})
  .post(function(req, res) {

   console.log(this.request.body);
});
我发现一些人报告了类似的问题,但提供的解决方案不适合我


有什么想法吗

在链接中描述了正确的解决方法,似乎我还有另一个错误。以下代码为我实现了这一点:

if (Meteor.isServer) {
    var Busboy = Meteor.npmRequire("busboy"),
        fs = Npm.require("fs"),
        os = Npm.require("os"),
        path = Npm.require("path");

    Router.onBeforeAction(function (req, res, next) {
        var filenames = []; // Store filenames and then pass them to request.
        _.extend(req, {postData: {}});

        if (req.method === "POST") {
            var busboy = new Busboy({ headers: req.headers });
            busboy.on("file", function (fieldname, file, filename, encoding, mimetype) {
                var saveTo = path.join(os.tmpDir(), filename);
                file.pipe(fs.createWriteStream(saveTo));
                filenames.push(saveTo);
            });
            busboy.on("field", function(fieldname, value) {
                req.postData[fieldname] = value;
            });
            busboy.on("finish", function () {
                // Pass filenames to request
                req.filenames = filenames;
                next();
            });
            // Pass request to busboy
            req.pipe(busboy);
        } else {
            this.next();
        }
    });
}
所需的路线如下所示:

 Router.route('/receive/', {where: 'server'})
  .post(function() {

  // Use this.request.postData to access the message content
  postData = this.request.postData;
});