37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
# coding:utf-8
|
|
from obs import ObsClient
|
|
|
|
|
|
def put_file(objectKey, file_path):
|
|
try:
|
|
obsClient = ObsClient(
|
|
access_key_id='UPEO770G619UPU8TU61Y',
|
|
secret_access_key='M7zVRT1pjRtGSZ2TOZwKBRoVJLeWAOf633kHaNcu',
|
|
server='https://obs.cn-east-2.myhuaweicloud.com'
|
|
)
|
|
resp = obsClient.putFile('legu-cdn-source', objectKey, file_path)
|
|
obsClient.close()
|
|
|
|
if resp.status < 300:
|
|
print('requestId:', resp.requestId)
|
|
print('etag:', resp.body.etag)
|
|
print('versionId:', resp.body.versionId)
|
|
print('storageClass:', resp.body.storageClass)
|
|
url: str = resp.body.objectUrl
|
|
url = url.replace('https://legu-cdn-source.obs.cn-east-2.myhuaweicloud.com', 'http://hw-obs-cdn.legu.cc')
|
|
return True, url
|
|
else:
|
|
print('errorCode:', resp.errorCode)
|
|
print('errorMessage:', resp.errorMessage)
|
|
return False, resp.errorMessage
|
|
|
|
except:
|
|
import traceback
|
|
|
|
print(traceback.format_exc())
|
|
return False, '上传文件未知错误'
|
|
|
|
|
|
if __name__ == '__main__':
|
|
put_file('bale.py', '/data/bale_apk/utils/bale.py')
|