以下是一个简单的腾讯云oss上传的python脚本:

import os
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client

# 设置腾讯云账户的密钥信息
secret_id = 'your_secret_id'
secret_key = 'your_secret_key'
region = 'your_region'  # 区域名称,例如:ap-guangzhou
token = None  # 使用临时密钥需要传入 Token,默认为空,可不填

# 设置上传的bucket和文件名
bucket = 'your_bucket'
file_path = 'your_file_path'

# 获取文件名和文件大小
file_name = os.path.basename(file_path)
file_size = os.path.getsize(file_path)

# 初始化配置
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token)
client = CosS3Client(config)

# 上传文件
response = client.upload_file(
    Bucket=bucket,
    LocalFilePath=file_path,
    Key=file_name,
    PartSize=10,
    MAXThread=10,
    EnableMD5=False
)

# 打印上传结果
print(response)

需要安装qcloud_cos库,可通过pip安装:

pip install qcloud_cos
编写一个腾讯云的oss 上传的python脚本

原文地址: https://www.cveoy.top/t/topic/bQwm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录