From 3c95ccdd8509ee524028fe2c3e15aa495b73cbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=A8?= Date: Thu, 23 Nov 2023 15:09:39 +0800 Subject: [PATCH] update edge --- floder/config.py | 17 ++++++++++++++++ utils/opfile.py | 21 ++++++++++---------- utils/up_load_file.py | 46 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 utils/up_load_file.py diff --git a/floder/config.py b/floder/config.py index cc7c37f..b441f04 100644 --- a/floder/config.py +++ b/floder/config.py @@ -15,3 +15,20 @@ _C.maskAreaImg1 = '../module/ieemoo-ai-conpurchase/model/now/maskAreaImg1.jpg' _C.streamModel = '../module/ieemoo-ai-conpurchase/model/now/raft-things.pth' _C.hFile = '../module/ieemoo-ai-conpurchase/document' _C.videoPath = '../module/ieemoo-ai-conpurchase/videos' + +#obs +_C.obs_access_key_id='LHXJC7GIC2NNUUHHTNVI' +_C.obs_secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM' +_C.obs_server='https://obs.cn-east-3.myhuaweicloud.com' +_C.obs_bucketName = 'ieemoo-ai' + +#cos +_C.cos_secret_id = 'AKIDIVcVFnBMMLCqbFF6lPr6930tc8VlrlS0' +_C.cos_secret_key = 'oYGrJG2d3LTUPBoFTZVEmC1kQ1ObdTkr' +_C.cos_region = 'ap-shanghai' +_C.cos_Bucket = 'ieemoo-ai-1321281601' + +#obs or cos +_C.obs = True +_C.cos = True + diff --git a/utils/opfile.py b/utils/opfile.py index 18020ae..fdb6e6b 100644 --- a/utils/opfile.py +++ b/utils/opfile.py @@ -1,15 +1,8 @@ -import h5py, os +import h5py, os, sys, logging, obs from floder.config import cfg -from obs import ObsClient -import obs -obsClient = ObsClient( -access_key_id='LHXJC7GIC2NNUUHHTNVI', -secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM', -server='https://obs.cn-east-3.myhuaweicloud.com') -bucketName = 'ieemoo-ai' -headers = obs.SetObjectMetadataHeader() -headers.cacheControl = "no-cache" +from up_load_file import up_load +up_load_data = up_load() def writef(uuid, num_id, feature): fname = os.sep.join([cfg.hFile, uuid+'.h5']) if not os.path.exists(fname): @@ -36,4 +29,10 @@ def uploadf(video_name, num, file_path): time = video_name.split('-')[0] objectkey = video_name.split('.')[0]+'_'+str(num)+'.mp4' objectkey = 'conpurchase/'+time+'/'+objectkey - resp = obsClient.putFile(bucketName, objectkey, file_path, headers=headers) + up_load_data.upLoad(objectkey, file_path) + #if obs: + # obsClient, headers = obsInit() + # resp = obsClient.putFile(cfg.obs_bucketName, objectkey, file_path, headers=headers) + #if cos: + # upLoadCos(cfg.cos_Bucket, objectkey, file_path) + diff --git a/utils/up_load_file.py b/utils/up_load_file.py new file mode 100644 index 0000000..33cb6bd --- /dev/null +++ b/utils/up_load_file.py @@ -0,0 +1,46 @@ +from obs import ObsClient +import obs +from floder.config import cfg +from qcloud_cos import CosConfig,CosS3Client +from qcloud_cos.cos_exception import CosClientError, CosServiceError + +def obsInit(): + print('start init obs <<') + obsClient = ObsClient( + access_key_id=cfg.obs_access_key_id, + secret_access_key=cfg.obs_secret_access_key, + server=cfg.obs_server) + bucketName = cfg.obs_bucketName + headers = obs.SetObjectMetadataHeader() + headers.cacheControl = "no-cache" + return obsClient, headers + +def cosInit(): + print('start init cos <<') + secret_id = cfg.cos_secret_id + secret_key = cfg.cos_secret_key + region = cfg.cos_region + config = CosConfig(Region=region, Secret_id=secret_id, Secret_key=secret_key) + client = CosS3Client(config) + return client + +class up_load: + def __init__(self): + self.cosclient = cosInit() + self.obsclient, self.headers = obsInit() + + def upLoad(self, key=None, datapath=None): + # 使用高级接口断点续传,失败重试时不会上传已成功的分块(这里重试10次) + if cfg.cos: + for i in range(0, 10): + try: + response = self.cosclient.upload_file( + Bucket=cfg.cos_Bucket, + Key=key, + LocalFilePath=datapath) + break + except CosClientError or CosServiceError as e: + print(e) + if cfg.obs: + response = self.obsclient.putFile(cfg.obs_bucketName, key, datapath) + return response