Code

Changes between Version 3 and Version 4 of AmazonSimpleStorageService


Ignore:
Timestamp:
06/07/07 18:01:04 (7 years ago)
Author:
dobesv@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AmazonSimpleStorageService

    v3 v4  
    22Here's a class I created to integrate my site with amazon's storage service. 
    33 
    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. 
     4I 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 
     6You 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. 
    57 
    68This 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. 
     
    9496     
    9597    def get_url(self, instance): 
    96         print 'get_url called with instance %s'%instance 
    9798        bucket = self.get_bucket(instance) 
    9899        key = self.get_key(instance) 
    99         print 'key %s bucket %s'%(key, bucket) 
    100         import sys 
    101         sys.stdout.flush() 
    102100        if bucket and key: 
    103101            url = generator.make_bare_url(bucket, key) 
    104             print 'url', url 
    105             sys.stdout.flush() 
    106102            return url 
    107103        return None 
     
    171167             
    172168            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) 
    173172            bucket = new_data["%s_bucket"%self.name] 
    174173            if not bucket: 
     
    179178                if not content_type: 
    180179                    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) 
    182180            conn.put(bucket, key, S3.S3Object(new_content),  
    183181                     { 'x-amz-acl': 'public-read' , 'Content-Type': content_type})