- name
- tencent-cos-uploader
- description
- 使用腾讯云 COS Python SDK 上传指定本地文件到目标 Bucket,并生成可用于查看和下载的预签名访问链接。用户提到 COS、对象存储、Bucket、上传文件、临时分享链接、签名 URL、下载直链时使用此 skill。
Tencent COS Uploader
Overview
Use Tencent COS Python SDK to upload a local file and return presigned URLs for browser preview and file download.
Prerequisites
- Install dependency:
pip install cos-python-sdk-v5- Prepare COS credentials (env vars preferred):
COS_SECRET_IDCOS_SECRET_KEYCOS_REGIONCOS_BUCKETCOS_SESSION_TOKEN(optional, for temporary credentials)
Workflow
- Confirm required inputs:
- region (from --region or env) - bucket (from --bucket or env) - --file local file path - --key object key in bucket (default is filename)
- Run the script:
python3 scripts/cos_upload_and_presign.py \
--region ap-guangzhou \
--bucket my-bucket-1250000000 \
--file /absolute/path/to/file.pdf \
--key reports/2026/file.pdf \
--expires 3600- Return JSON output containing:
- view_url: GET presigned URL for viewing - download_url: presigned URL with attachment disposition - upload_result: SDK upload response
Script Parameters
--regionCOS region, optional ifCOS_REGIONexists--bucketbucket name with appid suffix, optional ifCOS_BUCKETexists--filelocal file path to upload, required--keyobject key in bucket, optional--expiresURL expiration seconds, default3600--secret-idoptional ifCOS_SECRET_IDexists--secret-keyoptional ifCOS_SECRET_KEYexists--session-tokenoptional ifCOS_SESSION_TOKENexists--schemehttpsorhttp, defaulthttps--download-filenamecustom filename for download prompt (optional)
Notes
- Keep
expiresas short as practical to reduce link leakage risk. download_urlis generated viaget_presigned_download_url;view_urlis generated viaget_presigned_url(Method='GET').- If
--keyis omitted, the script uses the source filename as object key.