腾讯云COS对象存储操作工具,支持文件上传、下载、列表和管理。
使用前需要设置以下环境变量:
bash
export COS_SECRET_ID="你的SecretId"
export COS_SECRET_KEY="你的SecretKey"
export COS_REGION="ap-beijing" # COS地域
export COS_BUCKET="examplebucket-1250000000" # Bucket名称
bash
python scripts/cos_ops.py upload /path/to/file.txt
默认按当前月份 YYYY/MM/filename 格式存储,例如 2024/03/report.pdf
bash
python scripts/cos_ops.py upload /path/to/file.txt --key "myfolder/report.pdf"
bash
python scripts/cos_ops.py upload /path/to/largefile.zip --advanced --part-size 10 --threads 20
bash
python scripts/cos_ops.py download "2024/03/report.pdf" /local/path/report.pdf
bash
# 列出所有文件
python scripts/cos_ops.py list
# 按前缀筛选
python scripts/cos_ops.py list --prefix "2024/03/"
# 指定bucket
python scripts/cos_ops.py list --prefix "logs/" --bucket "my-bucket-1250000000"
bash
python scripts/cos_ops.py delete "2024/03/report.pdf"
在Python代码中直接调用:
python
from cos_ops import upload_file, download_file, list_objects, delete_object
# 上传文件(自动按月管理)
upload_file('/path/to/file.txt')
# 指定对象键
upload_file('/path/to/file.txt', cos_key='custom/path/file.txt')
# 下载文件
download_file('2024/03/report.pdf', '/local/save/report.pdf')
# 列出文件
list_objects(prefix='2024/03/')
# 删除文件
delete_object('2024/03/report.pdf')
脚本默认使用当前年月作为存储前缀,实现按月管理:
YYYY/MM/ 目录下report.pdf 会存储为 2024/03/report.pdf详细API文档请查看 references/cos_api.md
方法说明upload_file()简单上传,文件流方式upload_file_advanced()高级上传,自动分块download_file()下载文件到本地list_objects()列出对象delete_object()删除单个对象
版本日期更新内容1.0.02026-03-31初始版本,支持上传、下载、列举、删除功能,按月文件管理