-*- coding=utf-8
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import sys
import logging
import uuid
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
secret_id = 'secret_id'
secret_key = 'secret_key'
region = 'ap-guangzhou'
scheme = 'https'
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)
client = CosS3Client(config)
#### 文件流简单上传(不支持超过5G的文件,推荐使用下方高级上传接口)
# 强烈建议您以二进制模式(binary mode)打开文件,否则可能会导致错误
def upload_file(filename):
uploadfilename = '{}-plan_high_resolution.png'.format(str(uuid.uuid4()))
with open(filename, 'rb') as fp:
response = client.put_object(
Bucket='qdyxmas-1309824832',
Body=fp,
Key=uploadfilename),
StorageClass='STANDARD',
EnableMD5=False
)
return uploadfilename
if __name__ == "__main__":
filename = r"D:\django_apiplatform\vue3\tencent-oss-sdk\plan_high_resolution.png"
upload_file(filename)