예제 #1
0
 def __init__(self, conf):
     self.conf = conf
     self.oss = OssAPI(
         conf['host'],
         conf['access_id'],
         conf['secret_access_key'],
     )
예제 #2
0
 def __init__(self, conf):
     super(OSSFile, self).__init__(conf)
     from oss.oss_api import OssAPI
     self.oss = OssAPI(
         conf['host'],
         conf['access_id'],
         conf['secret_access_key'],
     )
예제 #3
0
def save_to_oss(filename, uploadset):
    """将文件保存到OSS上,若保存失败,则抛出IO异常"""
    config = current_app.config
    oss = OssAPI(config.get('OSS_HOST'), config.get('OSS_KEY'), config.get('OSS_SECRET'))
    res = oss.put_object_from_file("xichuangzhu", filename,
                                   uploadset.config.destination + '/' + filename)
    if res.status != 200:
        raise IOError
예제 #4
0
def save_to_oss(filename, uploadset):
    """将文件保存到OSS上,若保存失败,则抛出IO异常"""
    oss = OssAPI(config.OSS_HOST, config.OSS_KEY, config.OSS_SECRET)
    res = oss.put_object_from_file(
        "xichuangzhu", filename, uploadset.config.destination + '/' + filename)
    status = res.status
    if status != 200:
        raise IOError
예제 #5
0
 def connection(self):
     if self._connection is None:
         self._connection = OssAPI(
             host=self.access_endpoint,
             access_id=self.access_key,
             secret_access_key=self.access_secret,
             port=self.access_port,
             is_security=self.is_security,
             sts_token=self.sts_token,
         )
     return self._connection
예제 #6
0
def alioss_file_util(optype, fpath, content = ""):
    from oss.oss_api import OssAPI
    bucketname = settings["oss_bucket_name"]
    endpoint = settings["oss_endpoint"]
    accessKeyId, accessKeySecret = settings['oss_accessKeyId'], settings['oss_accessKeySecret']
    oss = OssAPI(endpoint, accessKeyId, accessKeySecret)
    if optype == 'read':
        res = oss.get_object(bucketname, fpath)
        return res.read() or ""
    elif optype == 'write':
        res = oss.put_object_from_string(bucketname, fpath, content)
        return True
    return ''
        list_data = f.read()
        upload_list = list_data.splitlines()

    if list_data == '':
        break

    object_name = upload_list[0]
    total = len(upload_list)
    with open(list_file, 'wb') as f:
        f.write('/n'.join(upload_list[1:]))

    print str(total), 'files to upload...'
    try:
        filename = filedir + object_name

        oss = OssAPI(upload_endpoint, access_id, access_key)
        upload_id = ElementTree.fromstring(
            oss.init_multi_upload(upload_bucket,
                                  object_name).read()).find('UploadId').text

        file_size = os.path.getsize(filename)
        pos_list = range(0, file_size, patch_size)
        len_list = [patch_size] * int(file_size / patch_size) + [
            file_size % patch_size
        ]
        part_id_list = range(1, len(pos_list) + 1)
        md5_list = range(len(pos_list))

        thread_pool = []
        for index, part_id in enumerate(part_id_list):
            upload_thread = UploadThread(oss, filename, pos_list, len_list,
예제 #8
0
#coding=utf-8
import os
from oss.oss_api import OssAPI

BUCKET_NAME = "fzx-backup"
oss = OssAPI("oss.aliyuncs.com", "", "")

part = 'crontab.txt'
part_filename = './crontab.txt'
res = oss.put_object_from_file(BUCKET_NAME, part, part_filename)
if res.status == 200:
    print "ok"
else:
    print "not ok"

#EOP

예제 #9
0
 def __init__(self):
     self.url = None
     self.filename = None
     self.oss = OssAPI(END_POINT, ACCESS_ID, ACCESS_KEY)
예제 #10
0
 def __init__(self, access_id, secret_access_key, bucket_name, host=None):
     super(OSSBackend, self).__init__()
     self.bucket_name = bucket_name
     self.oss = OssAPI(host or OSS_HOST, access_id, secret_access_key)
예제 #11
0
 def __init__(self, conf):
     self.conf = conf
     # Due to a bug in httplib we can't use https
     self.oss = OssAPI(conf.host, conf.key_id, conf.key)
예제 #12
0
 def __init__(self, access_key, access_key_secret, bucket, endpoint):
     self.access_key = access_key
     self.access_key_secret = access_key_secret
     self.bucket = bucket
     self.endpoint = endpoint
     self.oss = OssAPI(endpoint, access_key, access_key_secret)