Files
ocr/test008.py
2025-08-14 16:04:59 +08:00

29 lines
856 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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())