Skip to content
Browse files

add the s3 handling to be able to handle mybucket.s3...

  • Loading branch information...
1 parent b391fd5 commit a5b7c9aeef764b56858fd3e8d46cfd69f16eeee6 @git001 git001 committed Mar 27, 2012
Showing with 20 additions and 5 deletions.
  1. +5 −1 r2/example.ini
  2. +15 −4 r2/r2/lib/media.py
View
6 r2/example.ini
@@ -367,7 +367,11 @@ s3_media_buckets =
# For the bucket mybucket with the image helloworld.jpg the stored url would be:
# true: http://s3.amazonaws.com/mybucket/helloworld.jpg
# false: http://mybucket/helloworld.jpg
-s3_media_direct = true
+s3_media_direct = false
+
+# true: http://mybucket.s3.amazonaws.com/helloworld.jpg
+# false && s3_media_direct==true: http://s3.amazonaws.com/mybucket/helloworld.jpg
+s3_media_bucket_prefix=true
media_domain = localhost
# Embedly API Key
View
19 r2/r2/lib/media.py
@@ -49,6 +49,20 @@
MEDIA_FILENAME_LENGTH = 12
+def create_thumbnail_url(bucket,file_name,file_type):
+
+ if g.s3_old_thumb_bucket:
+ bucket = g.s3_old_thumb_bucket
+ baseurl = "http://%s" % (bucket)
+
+ if g.s3_media_direct:
+ baseurl = "http://%s/%s" % (s3_direct_url, bucket)
+
+ if g.s3_media_bucket_prefix:
+ baseurl = "http://%s.%s" %(bucket,s3_direct_url)
+
+ res = '%s/%s%s' % (baseurl,file_name,file_type)
+ return res
def thumbnail_url(link):
"""Given a link, returns the url for its thumbnail based on its fullname"""
@@ -77,10 +91,7 @@ def s3_upload_media(data, file_name, file_type, mime_type, never_expire):
never_expire=never_expire,
replace = False,
reduced_redundancy=True)
- if g.s3_media_direct:
- return "http://%s/%s/%s%s" % (s3_direct_url, bucket, file_name, file_type)
- else:
- return "http://%s/%s%s" % (bucket, file_name, file_type)
+ return create_thumbnail_url(bucket,file_name,file_type)
def get_filename_from_content(contents):
sha = hashlib.sha1(contents).digest()

0 comments on commit a5b7c9a

Please sign in to comment.
Something went wrong with that request. Please try again.