init
This commit is contained in:
28
test008.py
Normal file
28
test008.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import uuid
|
||||
from obs import ObsClient
|
||||
import os
|
||||
import traceback
|
||||
|
||||
ak = "HZDE30KAN5C5OLJ9JCCF"
|
||||
sk = "3QO1IJNRrFZyER1e1NBBu4qSyqDfZ8Xup0YPzDFW"
|
||||
|
||||
server = "https://obs.cn-north-1.myhuaweicloud.com"
|
||||
obsClient = ObsClient(access_key_id=ak, secret_access_key=sk, server=server)
|
||||
try:
|
||||
bucketName = "dsideal"
|
||||
# 对象名,即上传后的文件名
|
||||
objectKey = str(uuid.uuid4()) + ".jpg"
|
||||
# 待上传文件的完整路径,如aa/bb.txt
|
||||
file_path = "./img04.jpg"
|
||||
# 文件上传
|
||||
resp = obsClient.putFile(bucketName, objectKey, file_path)
|
||||
|
||||
# 返回码为2xx时,接口调用成功,否则接口调用失败
|
||||
if resp.status < 300:
|
||||
print('Put File Succeeded')
|
||||
print('文件地址:', resp.body.objectUrl)
|
||||
else:
|
||||
print('Put File Failed')
|
||||
except:
|
||||
print('Put File Failed')
|
||||
print(traceback.format_exc())
|
Reference in New Issue
Block a user