铁路由器使用Meteor.call抛出的动作writeHead不是一个函数

我试图写一个从服务器返回到客户端响应的缓冲区。

因此,我定义了一个在action函数上运行获取文件的path:

 Router.route('/download/:blabla', { name: 'download', action: function () { var that = this.response; Meteor.call('downloadFile', blabla, function (err, result) { // error check etc. var headers = { 'Content-type' : 'application/octet-stream', 'Content-Disposition' : 'attachment; filename=' + fileName }; that.writeHead(200, headers); that.end(result); } } }); 

这抛出:

传递调用“downloadFile”结果的exception:TypeError:that.writeHead不是函数

没有Metoer.call它的作品…

我使用nodejsstream来获取服务器端的缓冲区function,它的工作原理。

提前致谢

你有没有尝试过在服务器端使用IR路由? 即,使服务器上的路由只能通过“{where:”server“}”来访问,以避免必须按照下面的示例从这里进行方法调用(注意在文件中服务文件int他的示例需要添加logging:npm包根据意见,但你可能能够避免这个…):

 Router.route("/file/:fileName", function() { var fileName = this.params.fileName; // Read from a file (requires 'meteor add meteorhacks:npm') var filePath = "/path/to/pdf/store/" + fileName; var fs = Meteor.npmRequire('fs'); var data = fs.readFileSync(filePath); this.response.writeHead(200, { "Content-Type": "application/pdf", "Content-Length": data.length }); this.response.write(data); this.response.end(); }, { where: "server" });