diff --git a/floder/config.py b/floder/config.py index b441f04..ddd24e7 100644 --- a/floder/config.py +++ b/floder/config.py @@ -28,7 +28,13 @@ _C.cos_secret_key = 'oYGrJG2d3LTUPBoFTZVEmC1kQ1ObdTkr' _C.cos_region = 'ap-shanghai' _C.cos_Bucket = 'ieemoo-ai-1321281601' +#s3 +_C.s3_secret_id = 'v1wAfxqZqJYbA7kuB9dc' +_C.s3_secret_key = 'ZICGRJetjNIXhnqH1yfraoigydWoF2WTggtO9AhR' +_C.s3_region = '172.16.0.186:9000' +_C.s3_Bucket = 'ieemoo-ai' + #obs or cos _C.obs = True -_C.cos = True - +_C.cos = False +_C.s3 = True diff --git a/utils/up_load_file.py b/utils/up_load_file.py index 33cb6bd..4a7df00 100644 --- a/utils/up_load_file.py +++ b/utils/up_load_file.py @@ -3,6 +3,8 @@ import obs from floder.config import cfg from qcloud_cos import CosConfig,CosS3Client from qcloud_cos.cos_exception import CosClientError, CosServiceError +from minio import Minio +from minio.error import S3Error def obsInit(): print('start init obs <<') @@ -24,13 +26,27 @@ def cosInit(): client = CosS3Client(config) return client +def s3Init(): + print('start init s3 <<') + secret_id = cfg.s3_secret_id + secret_key = cfg.s3_secret_key + region = cfg.s3_region + client = Minio(region, secure=False, access_key=secret_id, secret_key=secret_key) + return client + + class up_load: def __init__(self): - self.cosclient = cosInit() - self.obsclient, self.headers = obsInit() + if cfg.cos: + self.cosclient = cosInit() + if cfg.obs: + self.obsclient, self.headers = obsInit() + if cfg.s3: + self.s3client = s3Init() def upLoad(self, key=None, datapath=None): # 使用高级接口断点续传,失败重试时不会上传已成功的分块(这里重试10次) + response = 'get re' if cfg.cos: for i in range(0, 10): try: @@ -43,4 +59,10 @@ class up_load: print(e) if cfg.obs: response = self.obsclient.putFile(cfg.obs_bucketName, key, datapath) + if cfg.s3: + found = self.s3client.bucket_exists(cfg.s3_Bucket) + if not found: + self.s3client.make_bucket(cfg.s3_Bucket) + self.s3client.fput_object(cfg.obs_bucketName, key, datapath) return response +