拒绝直接访问S3文件 [英] deny direct access to file on S3
问题描述
我是建设有以下行为的Django / S3应用:
I am building a django/s3 application with the following behaviour:
- 在用户登录
- 用户上传的文档 - (最终与UID的名称,并在数据库别名)>文件进入S3
- 用户可以下载该文件
我在寻找一种方式来拒绝其他用户(或者更糟糕,没有登录)来查询和获取文件。一个解决方案,我可以找到的是:
I'm looking for a way to deny the other users (or, even worse, not logged) to query and get access to the files. One solution I could find is:
- 的每个文件,页面有链接到一个处理脚本
- 链接被点击的时候,视图处理它(支票用户进行身份验证,确定S3正确的文件),并重定向到它
难道这还不够?是否有更优雅的解决方案,这一点?
Is this enough? Are there more elegant solutions to this?
推荐答案
不要让你的文件公开。这将prevent非授权用户访问这些文件。
Don't make your files public. This will prevent non-authorised users from accessing the files.
然后,在你的Django应用程序,您可以生成URL与查询字符串,它允许授权用户访问S3文件,在有限的时间。
Then in your Django app, you can generate urls with a querystring that allows an authorised user to access an S3 file for a limited time.
亚马逊的文档的<一个href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html#RESTAuthenticationQueryStringAuth"相对=nofollow>查询字符串的请求验证有更多的信息。
The amazon docs for querystring request authentication have more information.
这篇关于拒绝直接访问S3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!