Changes between Version 3 and Version 4 of AmazonSimpleStorageService
- Timestamp:
- Jun 7, 2007, 8:01:04 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
AmazonSimpleStorageService
v3 v4 2 2 Here's a class I created to integrate my site with amazon's storage service. 3 3 4 I like this because in the admin interface it looks pretty much like a file field and you can just click to upload. In theory you could integrate it into any oldforms system. Note that you have to set the amazon key, bucket, etc. manually, and that you have to put your amazon access keys into your site's settings module. 4 I like this because in the admin interface it looks pretty much like a file field and you can just click to upload. In theory you could integrate it into any oldforms system. 5 6 You can set a default bucket value for the entire system into your settings module or for specific fields. You can manually specify a key or let the class generate one for you. 5 7 6 8 This hasn't been tested extensively, so I invite you to contribute any fixes right here on the page. Maybe the django gods will see fit to include this right into django. … … 94 96 95 97 def get_url(self, instance): 96 print 'get_url called with instance %s'%instance97 98 bucket = self.get_bucket(instance) 98 99 key = self.get_key(instance) 99 print 'key %s bucket %s'%(key, bucket)100 import sys101 sys.stdout.flush()102 100 if bucket and key: 103 101 url = generator.make_bare_url(bucket, key) 104 print 'url', url105 sys.stdout.flush()106 102 return url 107 103 return None … … 171 167 172 168 key = new_data["%s_key"%self.name] 169 if not key: 170 key = "_".join((new_object.__class__.__name__.lower(), str(new_object.id), self.name)) 171 self.set_key(new_object, key) 173 172 bucket = new_data["%s_bucket"%self.name] 174 173 if not bucket: … … 179 178 if not content_type: 180 179 content_type = "application/x-octet-stream" 181 print 'Uploading %d bytes of data to bucket %s key %s filename %s'%(len(new_content), bucket, key, new_filename)182 180 conn.put(bucket, key, S3.S3Object(new_content), 183 181 { 'x-amz-acl': 'public-read' , 'Content-Type': content_type})