Django作为S3代理 [英] Django as S3 proxy

查看:167
本文介绍了Django作为S3代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自定义字段下载文件扩展了一个ModelAdmin,该文件是Django项目中URL的链接,如:

I extended a ModelAdmin with a custom field "Download file", which is a link to a URL in my Django project, like:

http://www.myproject.com/downloads/1

在那里,我想以提供存储在S3-bucket中的文件。桶中的文件不可读,用户可能没有直接访问它。现在我想要

There, I want to serve a file which is stored in a S3-bucket. The files in the bucket are not public readable, and the user may not have direct access to it. Now I want to


  • 避免文件必须加载到服务器内存中(这些是多gb文件)

  • 避免在服务器上有临时文件

理想的解决方案是让django作为代理将S3块块直接传递给用户。我使用boto,但没有找到流块的可能性。
任何想法?

The ideal solution would be to let django act as a proxy that streams S3-chunks directly to the user. I use boto, but did not find a possibility to stream the chunks. Any ideas?

谢谢。

推荐答案

比代理,为什么不简单地重定向?

Rather than proxying, why not simply redirect?

使用django视图在www.myproject.com/downloads/1为HTTP服务器提供一个HTTP重定向到S3存储URL - 这是可能的生成时间有限的认证URL,例如见这里 http://docs.amazonwebservices.com/AmazonS3/2006-03 -01 / dev /

Use the django view at www.myproject.com/downloads/1 to serve a HTTP Redirect to the S3 storage URL - it's possible to generate time-limited authenticated URLs e.g. see here http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/

然后,客户端直接从S3下载文件,但内容仍然是安全的,访问必须通过您的Django应用程序

Then the client downloads the file directly from S3, but the contents is still secure and access has to come through your Django application

这篇关于Django作为S3代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆