带Meteor的Filepicker.io:如何返回实际的资产,而不是指向资产的链接

我正在使用filepicker.io与Meteor应用程序,并正在为我的应用程序的安全性工作。 Filepicker为创build和签署策略提供支持,但在Meteor的服务器端,我觉得为每个请求文件的用户创build过期的策略是过度的。

我想要做的是提供给用户间接链接到一个文件。 服务器用服务器端路由(铁路由器)拦截这个请求,然后服务器通过带有关于所述文件的元数据的Files集合来检查用户是否具有该文件的许可。

就像我现在所做的那样,如果用户有访问权限,我会为他们提供一个带有签名和策略的文件链接作为该链接的参数。 相反,我宁愿只返回图像或文件资产,根本没有链接。 例如,服务器端将通过只有服务器知道的链接访问文件或映像,但是服务器会将该文件或映像stream式传输到客户端,而不共享到文件的实际链接。

预期的代码看起来像下面这样,我最终不知道该怎么做:

@route "file", path: "/file/:_id" where: "server" action: -> if @request.cookies.meteor_login_token user = Meteor.users.findOne( {"services.resume.loginTokens.hashedToken": Accounts._hashLoginToken(@request.cookies.meteor_login_token)} ) if user # the files collection has metadata about each file # these files are uploaded through filepicker # this include file.url which is the actual link file = share.Files.findOne( {_id: @params._id, accessibleBy: user._id} ) if not file @response.writeHead(403) @response.end() return else #return the file/image from filepicker, #eg file.url without actually returning the url @response.end() 

在我的研究中,似乎是一个stream可能是解决scheme,但对我来说,我不知道如何在node.js中使用光纤,就像在Meteor服务器端一样。

您可以使用webapp创build一个HTTP端点,然后使用node's httpFilepicker获取图像,然后将其传递给响应:

 var http = Npm.require('http'), url = Npm.require('url'); WebApp.connectHandlers.use('/file', function(req, res, next) { // URL format: /file/:_id var id = url.parse(req.url, true).path.substr(1); // this is _id // replace the following parameters with filepicker stuff http.request({ host: 'www.devbattles.com', path: '/en/images/upload/1427871558.png' }, function(result){ // here we just pipe the http result res.writeHead(200, { 'Content-Type': result.headers['content-type'] }); result.pipe(res); }).end(); }); 

如果您要将此代码(例如)复制到/server/filepickerPipe.js ,然后打开http://server.com/file/test ,则会看到此图片 。


作为一个方面说明:

有可能通过DDP服务所有这些。 我也将不得不开始从第三方提供文件,所以我可能会研究它,并创build一个包通过DDP执行,而不是与HTTP端点混乱。 但是,现在这是一个解决scheme。