拒绝直接访问 S3 上的文件
我正在构建一个具有以下行为的 django/s3 应用程序:
I am building a django/s3 application with the following behaviour:
- 用户登录
- 用户上传文档 -> 文档转到 S3(最终在数据库中具有 UID 名称和别名?)
- 用户可以下载文档
我正在寻找一种方法来拒绝其他用户(或者更糟糕的是,未登录)查询和访问文件.我能找到的一种解决方案是:
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?
不要公开您的文件.这将防止未经授权的用户访问文件.
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.
用于查询字符串请求身份验证的亚马逊文档 了解更多信息.