腾讯cos配置# -*- coding: UTF-8 -*-
'''=================================================
@Project -> File  :MyDjango -> cos_upload_demo
@IDE    :PyCharm
@Author :ruochen
@Date  :2020/7/17 11:52
@Desc  :
@Install: pip install -U cos-python-sdk-v5
=================================================='''
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
import uuid
secret_id = '⾃⼰id'  # 替换为⽤户的 secretId
secret_key = '⾃⼰key'  # 替换为⽤户的 secretKey
region = 'ap-nanjing'  # 替换为⽤户的 Region
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key)
client = CosS3Client(config)
filename = str(uuid.uuid4())
response = client.upload_file(
Bucket='xxxxxxx',
django登录注册功能LocalFilePath='xxxxx.png',  # 本地⽂件的路径
Key = filename,  # 上传到桶之后的⽂件名
)
print(response['ETag'])

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。