【发布时间】:2015-07-29 04:33:20
【问题描述】:
我正在将 filepicker.io 与 Meteor 应用程序一起使用,并且正在为我的应用程序开发安全性。 Filepicker 支持创建和签署策略,但对于 Meteor 的服务器端,我觉得为每个请求文件的用户创建过期策略是多余的。
我想做的是为用户提供一个文件的间接链接。服务器使用服务器端路由(iron-router)拦截此请求,然后服务器通过带有关于所述文件的元数据的 Files 集合检查用户是否具有文件权限。
正如我现在所拥有的,如果用户有权访问,我会向他们提供一个文件链接,其中包含签名和策略作为该链接的参数。相反,我宁愿只返回图像或文件资产,根本不返回链接。例如。服务器端将通过只有服务器知道的链接访问文件或图像,但服务器会将该文件或图像流式传输到客户端,而不共享文件的实际链接。
预期的代码如下所示,我真的不知道最后该做什么:
@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,
#e.g. file.url without actually returning the url
@response.end()
在我的研究中,stream 似乎是解决方案,但对我来说,我将如何在 node.js Fiber 中做到这一点并不明显,就像 Meteor 服务器端的情况一样。
【问题讨论】:
-
最简单的解决方案是将用户重定向到文件选择器链接。但是,如果您不想显示用户真实链接,则需要从 filepicker url 读取数据并从您的域返回。
-
我猜可能是这样。我想真正的问题是我是否需要先将其下载到服务器,或者是否有某种方法可以轻松地在外部 URL、我的服务器和客户端之间传输数据。我已经看到一些提到使用 AWS/S3 的 nodejs 中的流,但没有像 Meteor 服务器那样在 Fiber 中这样做。
标签: node.js security meteor server-side filepicker.io