David Larlet avatar David Larlet committed f1b973d

S3 Boto: More flexibility thanks to settings from Wim Leers' patch (#5) and Mads Sülau Jørgensen's fork

Comments (0)

Files changed (1)


-AWS_BUCKET_PREFIX = getattr(settings, AWS_BUCKET_NAME, {})
+BUCKET_PREFIX     = getattr(settings, BUCKET_NAME, {})
+HEADERS           = getattr(settings, HEADERS, {})
+DEFAULT_ACL       = getattr(settings, DEFAULT_ACL, 'public-read')
 class S3BotoStorage(Storage):
     """Amazon Simple Storage Service using Boto"""
-    def __init__(self, bucket="root", bucketprefix=AWS_BUCKET_PREFIX, 
-            access_key=None, secret_key=None, acl='public-read'):
+    def __init__(self, bucket="root", bucketprefix=BUCKET_PREFIX, 
+            access_key=None, secret_key=None, acl=DEFAULT_ACL, headers=HEADERS):
         self.acl = acl
+        self.headers = headers
         if not access_key and not secret_key:
              access_key, secret_key = self._get_access_keys()
         self.connection = S3Connection(access_key, secret_key)
         self.bucket = self.connection.create_bucket(bucketprefix + bucket)
-        self.headers = getattr(settings, AWS_HEADERS, {})
+        self.bucket.set_acl(self.acl)
     def _get_access_keys(self):
         access_key = getattr(settings, ACCESS_KEY_NAME, None)
         k = self.bucket.get_key(name)
         if not k:
             k = self.bucket.new_key(name)
-        k.set_contents_from_file(content)
+        k.set_contents_from_file(content, headers=self.headers, policy=self.acl)
         return name
     def delete(self, name):
         return self.bucket.get_key(name).size
     def url(self, name):
-        return self.bucket.get_key(name).generate_url(3600, method='GET')
+        return self.bucket.get_key(name).generate_url(QUERYSTRING_EXPIRE, method='GET')
     def get_available_name(self, name):
         """ Overwrite existing file with the same name. """
         return self.key.read(*args, **kwargs)
     def write(self, content):
-        self.key.set_contents_from_string(content)
+        self.key.set_contents_from_string(content, headers=self._storage.headers, acl=self._storage.acl)
     def close(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.