Skip to content

Commit

Permalink
Merge pull request #1 from dt3310321/s3
Browse files Browse the repository at this point in the history
S3
  • Loading branch information
dt3310321 authored Aug 26, 2017
2 parents db3c111 + 510fa19 commit c008772
Show file tree
Hide file tree
Showing 12 changed files with 1,065 additions and 166 deletions.
32 changes: 15 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
sudo: false
language: python

python:
- "2.6"
- "2.7"

install:
- pip install requests
- pip install nose
- pip install pep8
- pip install tox

script:
- pep8 --max-line-length=180
- nosetests -s
- tox
sudo: false
language: python

python:
- "2.6"
- "2.7"

install:
- pip install requests
- pip install nose
- pip install pep8

script:
- pep8 --max-line-length=180 qcloud_cos/.
- nosetests -s -v
Empty file removed README.md
Empty file.
131 changes: 131 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
Qcloud COSv5 SDK
#######################

介绍
_______

腾讯云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

.. code:: python
# 设置用户属性, 包括appid, secret_id和secret_key
appid = 100000 # 替换为用户的appid
secret_id = u'xxxxxxxx' # 替换为用户的secret_id
secret_key = u'xxxxxxx' # 替换为用户的secret_key
  region = "cn-north"       # 替换为用户的region,目前可以为 cn-east/cn-south/cn-north/cn-southwest,分别对应于上海,广州,天津,西南园区
config = CosConfig(Appid=appid, Region=region, Access_id=secret_id, Access_key=secret_key) #获取配置对象
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']
# 10. 完成分片上传
response = client.complete_multipart_upload(
Bucket='test01',
Key='multipartfile.txt',
UploadId=uploadid,
MultipartUpload={'Part': lst}
)
############################################################################
# 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'
)
8 changes: 5 additions & 3 deletions qcloud_cos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import cos_auth
import cos_threadpool
import cos_client
from .cos_client import CosS3Client
from .cos_client import CosConfig
from .cos_exception import CosServiceError
from .cos_exception import CosClientError
from .cos_auth import CosS3Auth
7 changes: 3 additions & 4 deletions qcloud_cos/cos_auth.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-

import hmac
import time
import urllib
import hashlib
import logging
import requests
from urllib import quote
from urlparse import urlparse
from requests.auth import AuthBase
logger = logging.getLogger(__name__)

#fix a bug which can't send header

class CosS3Auth(AuthBase):

def __init__(self, access_id, secret_key, expire=10000):
Expand Down Expand Up @@ -71,5 +71,4 @@ def __call__(self, r):


if __name__ == "__main__":
url = 'http://lewzylu01-1252448703.cn-south.myqcloud.com/a.txt'

pass
Loading

0 comments on commit c008772

Please sign in to comment.