在鏈接中描述了正確的解決方法,好像我還有另一個錯誤。下面的代碼爲我做的伎倆:
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;
});