静态资源的访问控制
在我的应用程序中,我有时会生成一张新图片。阅读此处的评论后我决定将图片存储在文件系统中,将元数据存储在数据库中,所以现在我的文件独立于数据库静态提供(bd 为用户提供他们想要访问的文件名,然后他们从静态文件中提取该文件名)文件服务器)。
然而,我这里遇到的问题是,我并不总是希望用户看到其他用户生成的图片。举例来说,用户 Joe 创建图片 A 和 B,用户 Sue 创建图片 C 和 D。我不希望 Joe 能够看到 C 和 D,也不希望 Sue 看到 A 和 B。因为所有文件都是静态提供的,如果 Joe 碰巧猜到了 C 的 url,他就可以访问它。
由于图片的提供方式几乎不受我的 django 的控制,我不确定这里的解决方案是什么,除了加密文件(这是复杂且资源密集型的)
In my application I sometimes generate a new picture. After reading comments here I decided to store the pictures in the filesystem and the metadata in the database, so now my files are served statically independently of the database (the bd gives the user the filename that they want to access, which they then pull from a static fileserver).
However, the problem I have here is that I don't always want users to see pictures generated by other users. Let's say, for example, that user Joe creates pictures A and B, and user Sue creates C and D. I don't want Joe being able to see C and D and I dont want Sue seeing A and B. Since all the files are served statically, if Joe happens to guess the url for C, he can access it.
Since the way the pictures are served is pretty much out of control of my django, I'm not sure what the solution here would be, other than encrypting the files (which is complicated and resource-intensive)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是使用 django send_file[1] 来完成。这很容易实现,但扩展性不佳。我用它来提供动态生成的报告。这个解决方案的唯一优点是它都是 python 代码。
更好的方法是使用三麦链接上的信息。您还可以在这里查看: http://www.sensibledevelopment.com/2010/11/django-sendfile-an-for-abstraction-large-file-serving-in-django/ 了解一些 django 特定信息。
1:http://djangosnippets.org/snippets/101/
The easy way is to use django send_file[1] to do it. This is easy to implement but does not scale well. I use it to serve dynamically generated reports. The only advantage of this solution is that it's all python code.
The better way is to use the information on sanmai's links. You can also take a look here: http://www.sensibledevelopment.com/2010/11/django-sendfile-an-for-abstraction-large-file-serving-in-django/ for some django specific information.
1: http://djangosnippets.org/snippets/101/
使用某个属性的一个或多个MD5十六进制摘要作为图像路径的一部分;路径将是相当随机的。
Use one or more MD5 hexdigest of some attribute as part of the image path; the path will be pretty random.