S3
This commit is contained in:
@ -28,7 +28,13 @@ _C.cos_secret_key = 'oYGrJG2d3LTUPBoFTZVEmC1kQ1ObdTkr'
|
|||||||
_C.cos_region = 'ap-shanghai'
|
_C.cos_region = 'ap-shanghai'
|
||||||
_C.cos_Bucket = 'ieemoo-ai-1321281601'
|
_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
|
#obs or cos
|
||||||
_C.obs = True
|
_C.obs = True
|
||||||
_C.cos = True
|
_C.cos = False
|
||||||
|
_C.s3 = True
|
||||||
|
@ -3,6 +3,8 @@ import obs
|
|||||||
from floder.config import cfg
|
from floder.config import cfg
|
||||||
from qcloud_cos import CosConfig,CosS3Client
|
from qcloud_cos import CosConfig,CosS3Client
|
||||||
from qcloud_cos.cos_exception import CosClientError, CosServiceError
|
from qcloud_cos.cos_exception import CosClientError, CosServiceError
|
||||||
|
from minio import Minio
|
||||||
|
from minio.error import S3Error
|
||||||
|
|
||||||
def obsInit():
|
def obsInit():
|
||||||
print('start init obs <<')
|
print('start init obs <<')
|
||||||
@ -24,13 +26,27 @@ def cosInit():
|
|||||||
client = CosS3Client(config)
|
client = CosS3Client(config)
|
||||||
return client
|
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:
|
class up_load:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cosclient = cosInit()
|
if cfg.cos:
|
||||||
self.obsclient, self.headers = obsInit()
|
self.cosclient = cosInit()
|
||||||
|
if cfg.obs:
|
||||||
|
self.obsclient, self.headers = obsInit()
|
||||||
|
if cfg.s3:
|
||||||
|
self.s3client = s3Init()
|
||||||
|
|
||||||
def upLoad(self, key=None, datapath=None):
|
def upLoad(self, key=None, datapath=None):
|
||||||
# 使用高级接口断点续传,失败重试时不会上传已成功的分块(这里重试10次)
|
# 使用高级接口断点续传,失败重试时不会上传已成功的分块(这里重试10次)
|
||||||
|
response = 'get re'
|
||||||
if cfg.cos:
|
if cfg.cos:
|
||||||
for i in range(0, 10):
|
for i in range(0, 10):
|
||||||
try:
|
try:
|
||||||
@ -43,4 +59,10 @@ class up_load:
|
|||||||
print(e)
|
print(e)
|
||||||
if cfg.obs:
|
if cfg.obs:
|
||||||
response = self.obsclient.putFile(cfg.obs_bucketName, key, datapath)
|
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
|
return response
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user