Skip to main content

cos-python-sdk-v5

Project description

介绍

腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7。

安装指南

使用pip安装

pip install -U cos-python-sdk-v5

手动安装:

python setup.py install

使用方法

使用python sdk,参照https://github.com/tencentyun/cos-python-sdk-v5/blob/master/qcloud_cos/test.py

cos最新可用地域,参照https://www.qcloud.com/document/product/436/6224

# 设置用户属性, 包括appid, secret_id, secret_key, region
appid = '100000'           # 替换为用户的appid
secret_id = 'xxxxxxxx'     # 替换为用户的secret_id
secret_key = 'xxxxxxx'     # 替换为用户的secret_key
region = 'ap-beiging-1'    # 替换为用户的region
token = ''                 # 使用临时秘钥需要传入Token,默认为空,可不填
config = CosConfig(Appid=appid, Region=region, Access_id=secret_id, Access_key=secret_key, Token=token)  #获取配置对象
client = CosS3Client(config)                                                                #获取客户端对象


############################################################################
# 文件操作                                                                 #
############################################################################
# 1. 上传单个文件
response = client.put_object(
    Bucket='test01',
    Body='TY'*1024*512*file_size,
    Key=file_name,
    CacheControl='no-cache',
    ContentDisposition='download.txt'
)

# 2. 下载单个文件
response = client.get_object(
    Bucket='test01',
    Key=file_name,
)

# 3. 获取文件属性
response = client.head_object(
    Bucket='test01',
    Key=file_name
)

# 4. 删除单个文件
response = client.delete_object(
    Bucket='test01',
    Key=file_name
)

# 5. 创建分片上传
response = client.create_multipart_upload(
    Bucket='test01',
    Key='multipartfile.txt',
)
uploadid = get_id_from_xml(response.text)

# 6. 删除分片上传
response = client.abort_multipart_upload(
    Bucket='test01',
    Key='multipartfile.txt',
    UploadId=uploadid
)

# 7. 再次创建分片上传
response = client.create_multipart_upload(
    Bucket='test01',
    Key='multipartfile.txt',
)
uploadid = response['UploadId']

# 8. 上传分片
response = client.upload_part(
    Bucket='test01',
    Key='multipartfile.txt',
    UploadId=uploadid,
    PartNumber=1,
    Body='A'*1024*1024*4
)
etag = response['ETag']

# 9. 列出分片
response = clieent.list_parts(
    Bucket='test01',
    Key='mutilpartfile.txt',
    UploadId=uploadid
)
lst = response['Part'] # list_parts最大数量为1000

# 10. 完成分片上传
response = client.complete_multipart_upload(
    Bucket='test01',
    Key='multipartfile.txt',
    UploadId=uploadid,
    MultipartUpload={'Part': lst} # 超过1000个分块,请本地保存分块信息,再complete
)


############################################################################
# Bucket操作                                                                 #
############################################################################
# 1. 创建Bucket
response = client.create_bucket(
    Bucket='test02',
    ACL='public-read'
)

# 2. 删除Bucket
response = client.delete_bucket(
    Bucket='test02'
)

# 3. 获取文件列表
response = client.list_objects(
    Bucket='test01'
)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cos-python-sdk-v5-1.1.0.linux-x86_64.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

cos_python_sdk_v5-1.1.0-py2-none-any.whl (20.2 kB view details)

Uploaded Python 2

File details

Details for the file cos-python-sdk-v5-1.1.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for cos-python-sdk-v5-1.1.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 da694ef68083f0462d4254da24b36960b409d6d4a05010a580b63ad70130857a
MD5 cc033401b47e074009f394864e908799
BLAKE2b-256 14efa6e88f5d9a0a7bff070c808b33eca9c86d32bb0763253008c5772879d903

See more details on using hashes here.

File details

Details for the file cos_python_sdk_v5-1.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for cos_python_sdk_v5-1.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 74d1b61630dbf6a211b17b38dcf9fc3a4e3de786dbbfe00b73bb444921b569bd
MD5 90553713c044b1f2b2f76f6f3f4cf88d
BLAKE2b-256 1404e750b5aea2e6f0984bbf4c4ccb5d4468e78fdd82d555d7ebb98ca17dc076

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page