oss连接的简单实现与文件的简单获取

# -*- coding: utf-8 -*-
import oss2


class Test(object):
    def __init__(self):
        self.auth = oss2.Auth('LTAIwW2SiGVPJ4IL', 'P7n5DFASr2WLwJQV3IAKpIAlqVP12p')  # 阿里账号
        self.bucket = oss2.Bucket(self.auth, 'http://oss-cn-beijing.aliyuncs.com', 'pacong')  # bucket对象

    def run(self):
        # auth = oss2.Auth('LTAIwW2SiGVPJ4IL', 'P7n5DFASr2WLwJQV3IAKpIAlqVP12p')  # 阿里账号
        # bucket = oss2.Bucket(auth, 'http://oss-cn-beijing.aliyuncs.com', 'pacong')  # bucket对象
        num = 0
        for obj in oss2.ObjectIterator(self.bucket, prefix='faxin_wenshu/Database_2014_1', max_keys=1000):
            print(obj.key)
            num += 1
        print(num)

    # object_stream = bucket.get_object(obj.key)
    # print(object_stream.read().decode())


if __name__ == '__main__':
    test = Test()
    test.run()

 

你可能感兴趣的:(平时积累)