Example #1
0
 def upload(self, name, fileobj, app):
     "Upload a file"
     # Raise exception if a file with the filename already exists
     if default_storage.exists(name):
         raise FileExists()
     
     cloudfile = CloudFile(name=name, content=fileobj, 
                           size=fileobj.size, app=app)
     cloudfile.save()
     return cloudfile
Example #2
0
    def save(self, filename, content, app):
        
        new_file = CloudFile(name=filename, app=app)
        conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
        key = new_file.get_upload_loc(filename)
        
        # Raise exception if a file with the filename already exists
        if default_storage.exists(key):
            raise FileExists()
        
        new_file.size = content.size
        new_file.content.save(filename, content)

        url = conn.generate_url(
            settings.AWS_URL_EXPIRY, "GET", bucket=settings.AWS_STORAGE_BUCKET_NAME, key=key)
        new_file.url = url
        new_file.save()
        return new_file