Skip to content

Commit 09c224d

Browse files
committed
add put/get bucket intelligenttiering
2 parents 9350823 + 082fe70 commit 09c224d

21 files changed

+2313
-107
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: ChangeLog
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/setup-node@v2-beta
15+
with:
16+
node-version: '12'
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Checkout Tool
22+
uses: actions/checkout@v2
23+
with:
24+
repository: konakonall/auto-changelog
25+
path: 'auto-changelog'
26+
- name: Build Tool
27+
run: |
28+
cd auto-changelog
29+
npm install
30+
npm link
31+
32+
- name: Generate ChangeLog
33+
env: # Or as an environment variable
34+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
run: |
36+
auto-changelog --token $TOKEN
37+
- name: Cat ChangeLog
38+
run: cat CHANGELOG.md
39+
40+
- name: Commit files
41+
env:
42+
CI_USER: "gouki0123"
43+
CI_EMAIL: "gouki0123@gmail.com"
44+
run: |
45+
git config --local user.email "$CI_EMAIL"
46+
git config --local user.name "$CI_USER"
47+
git add CHANGELOG.md && git commit -m 'Updated CHANGELOG.md' && echo "push=1" >> $GITHUB_ENV || echo "No changes to CHANGELOG.md"
48+
49+
- name: Push changes
50+
if: env.push == 1
51+
env:
52+
CI_USER: "gouki0123"
53+
CI_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
run: |
55+
git push "https://$CI_USER:$CI_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:master

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ python:
44
- '2.7'
55
- '3.5'
66
- '3.6'
7+
- '3.7'
78
install:
89
- pip install requests
910
- pip install six
1011
- pip install nose
1112
- pip install pycodestyle
1213
- pip install dicttoxml
1314
- pip install crcmod
15+
- pip install pycryptodome
1416
notifications:
1517
email:
1618
recipients:

CHANGELOG.md

Lines changed: 686 additions & 0 deletions
Large diffs are not rendered by default.

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ __________
2727
使用方法
2828
__________
2929

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

3232
cos最新可用地域,参照 https://cloud.tencent.com/document/product/436/6224
3333

demo/demo.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# -*- coding=utf-8
2+
from qcloud_cos import CosConfig
3+
from qcloud_cos import CosS3Client
4+
from qcloud_cos import CosServiceError
5+
from qcloud_cos import CosClientError
6+
7+
import sys
8+
import logging
9+
10+
# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x
11+
12+
# pip安装指南:pip install -U cos-python-sdk-v5
13+
14+
# cos最新可用地域,参照https://www.qcloud.com/document/product/436/6224
15+
16+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
17+
18+
# 设置用户属性, 包括secret_id, secret_key, region
19+
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成
20+
secret_id = 'secret_id' # 替换为用户的secret_id
21+
secret_key = 'secret_key' # 替换为用户的secret_key
22+
region = 'ap-beijing' # 替换为用户的region
23+
token = None # 使用临时密钥需要传入Token,默认为空,可不填
24+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
25+
client = CosS3Client(config)
26+
27+
# 文件流 简单上传
28+
file_name = 'test.txt'
29+
with open('test.txt', 'rb') as fp:
30+
response = client.put_object(
31+
Bucket='test04-123456789', # Bucket由bucketname-appid组成
32+
Body=fp,
33+
Key=file_name,
34+
StorageClass='STANDARD',
35+
ContentType='text/html; charset=utf-8'
36+
)
37+
print(response['ETag'])
38+
39+
# 字节流 简单上传
40+
response = client.put_object(
41+
Bucket='test04-123456789',
42+
Body=b'abcdefg',
43+
Key=file_name
44+
)
45+
print(response['ETag'])
46+
47+
# 本地路径 简单上传
48+
response = client.put_object_from_local_file(
49+
Bucket='test04-123456789',
50+
LocalFilePath='local.txt',
51+
Key=file_name,
52+
)
53+
print(response['ETag'])
54+
55+
# 设置HTTP头部 简单上传
56+
response = client.put_object(
57+
Bucket='test04-123456789',
58+
Body=b'test',
59+
Key=file_name,
60+
ContentType='text/html; charset=utf-8'
61+
)
62+
print(response['ETag'])
63+
64+
# 设置自定义头部 简单上传
65+
response = client.put_object(
66+
Bucket='test04-123456789',
67+
Body=b'test',
68+
Key=file_name,
69+
Metadata={
70+
'x-cos-meta-key1': 'value1',
71+
'x-cos-meta-key2': 'value2'
72+
}
73+
)
74+
print(response['ETag'])
75+
76+
# 高级上传接口(推荐)
77+
response = client.upload_file(
78+
Bucket='test04-123456789',
79+
LocalFilePath='local.txt',
80+
Key=file_name,
81+
PartSize=10,
82+
MAXThread=10
83+
)
84+
print(response['ETag'])
85+
86+
# 文件下载 获取文件到本地
87+
response = client.get_object(
88+
Bucket='test04-123456789',
89+
Key=file_name,
90+
)
91+
response['Body'].get_stream_to_file('output.txt')
92+
93+
# 文件下载 获取文件流
94+
response = client.get_object(
95+
Bucket='test04-123456789',
96+
Key=file_name,
97+
)
98+
fp = response['Body'].get_raw_stream()
99+
print(fp.read(2))
100+
101+
# 文件下载 设置Response HTTP 头部
102+
response = client.get_object(
103+
Bucket='test04-123456789',
104+
Key=file_name,
105+
ResponseContentType='text/html; charset=utf-8'
106+
)
107+
print(response['Content-Type'])
108+
fp = response['Body'].get_raw_stream()
109+
print(fp.read(2))
110+
111+
# 文件下载 指定下载范围
112+
response = client.get_object(
113+
Bucket='test04-123456789',
114+
Key=file_name,
115+
Range='bytes=0-10'
116+
)
117+
fp = response['Body'].get_raw_stream()
118+
print(fp.read())
119+
120+
# 文件下载 捕获异常
121+
try:
122+
response = client.get_object(
123+
Bucket='test04-123456789',
124+
Key='not_exist.txt',
125+
)
126+
fp = response['Body'].get_raw_stream()
127+
print(fp.read(2))
128+
except CosServiceError as e:
129+
print(e.get_origin_msg())
130+
print(e.get_digest_msg())
131+
print(e.get_status_code())
132+
print(e.get_error_code())
133+
print(e.get_error_msg())
134+
print(e.get_resource_location())
135+
print(e.get_trace_id())
136+
print(e.get_request_id())

demo/fetch_demo.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding=utf-8
2+
from qcloud_cos import CosConfig
3+
from qcloud_cos import CosS3Client
4+
from qcloud_cos import CosServiceError
5+
from qcloud_cos import CosClientError
6+
7+
import sys
8+
import logging
9+
10+
11+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
12+
13+
# 设置用户属性, 包括secret_id, secret_key, region
14+
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成
15+
secret_id = '' # 替换为用户的secret_id
16+
secret_key = '' # 替换为用户的secret_key
17+
region = 'ap-beijing' # 替换为用户的region
18+
token = None # 使用临时密钥需要传入Token,默认为空,可不填
19+
scheme = 'http'
20+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme) # 获取配置对象
21+
client = CosS3Client(config)
22+
23+
test_bucket = 'examplebucket-1250000000'
24+
# 发起拉取任务
25+
response = client.put_async_fetch_task(
26+
Bucket=test_bucket,
27+
FetchTaskConfiguration={
28+
'Url': 'http://examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject',
29+
'Key': 'exampleobject'
30+
}
31+
)
32+
33+
# 查询拉取任务
34+
response = client.get_async_fetch_task(
35+
Bucket=test_bucket,
36+
TaskId=response['data']['taskid']
37+
)

0 commit comments

Comments
 (0)