Beispiel #1
0
def get_img_url():
    img_dir = '/images'
    domain_name = 'fruitrepository'
    sae_storage_conn = Connection()
    tmp_bucket = sae_storage_conn.get_bucket(domain_name)
    dacl = tmp_bucket.generate_url('images/titlepic.jpg')
    return dacl
Beispiel #2
0
 def __init__(self,
              bucket_name=STORAGE_BUCKET_NAME,
              accesskey=STORAGE_ACCESSKEY,
              secretkey=STORAGE_SECRETKEY,
              account=STORAGE_ACCOUNT):
     conn = Connection(accesskey, secretkey, account)
     self.bucket = conn.get_bucket(bucket_name)
Beispiel #3
0
def save_image_return_url(filename, file):
    """ 
         return: the url of the image in the storage
    """
    c = Connection()
    bucket = c.get_bucket('images')
    bucket.put_object(filename, file.read())
    return bucket.generate_url(filename)
Beispiel #4
0
def save_image_return_url_sae(filename, file):
    """仅供本地调试使用
    """
    from sae.storage import Connection, Bucket
    c = Connection()
    bucket = c.get_bucket('images')
    bucket.put_object(filename, file.read())
    return bucket.generate_url(filename)
Beispiel #5
0
def del_pet(pet_id):
    kv = sae.kvdb.Client()
    image_url = kv.get(pet_id)['photo_url']
    object_name = image_url.split('/')[-1]
    kv.delete(pet_id)
    number = kv.get('petsnumber') - 1
    kv.replace('petsnumber', number)
    c = Connection()
    bucket = c.get_bucket('images')
    bucket.delete_object(object_name)
    kv.disconnect_all()
Beispiel #6
0
def get_sae_bucket():
    # from sae.storage import Bucket
    from sae.storage import Connection
    from exchcard import settings
    connection = Connection(accesskey=settings.DATABASES.MYSQL_USER,
                            secretkey=settings.DATABASES.MYSQL_PASS,
                            account="exchcard2",
                            retries=3)

    bucket = connection.get_bucket(settings.STORAGE_BUCKET_NAME)
    bucket.post(acl=".r:*", metadata={"expires": "1d"})

    return bucket
Beispiel #7
0
    def __init__(self, **kwargs):
        bucket = kwargs['bucket'] if 'bucket' in kwargs else ''
        accesskey = kwargs['accesskey'] if 'accesskey' in kwargs else ''
        secretkey = kwargs['secretkey'] if 'secretkey' in kwargs else ''
        account = kwargs['account'] if 'account' in kwargs else ''  # app name
        retries = long(
            kwargs['retries']) if 'retries' in kwargs else 3  # app name

        self.prefix = kwargs['prefix'] if 'prefix' in kwargs else ''

        if accesskey and secretkey and account:
            conn = Connection(accesskey, secretkey, account, retries)
            self.kv = conn.get_bucket(bucket)
        else:
            self.kv = Bucket(bucket)
 def __init__(self, bucket_name=STORAGE_BUCKET_NAME,
              accesskey=STORAGE_ACCESSKEY, secretkey=STORAGE_SECRETKEY,
              account=STORAGE_ACCOUNT):
     conn = Connection(accesskey, secretkey, account)
     self.bucket = conn.get_bucket(bucket_name)