views:

169

answers:

1
+1  Q: 

Django as S3 proxy

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

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

  • avoid that the file has to be loaded in the server memory (these are multi-gb-files)
  • avoid to have temp files on the server

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?

Thanks.

+1  A: 

Rather than proxying, why not simply redirect?

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/

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

Malcolm Box