Skip to content

Commit 338498c

Browse files
authored
Merge pull request #238 from bug-is-zhang/master
文件处理SDK集成
2 parents afb3b1c + 816fb90 commit 338498c

File tree

2 files changed

+447
-3
lines changed

2 files changed

+447
-3
lines changed

demo/ci_file_process.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# -*- coding=utf-8
2+
3+
from qcloud_cos import CosConfig
4+
from qcloud_cos import CosS3Client
5+
6+
import os
7+
import sys
8+
import logging
9+
10+
# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x
11+
12+
# https://cloud.tencent.com/document/product/436/46782
13+
14+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
15+
16+
# 设置用户属性, 包括 secret_id, secret_key, region等。Appid 已在CosConfig中移除,请在参数 Bucket 中带上 Appid。Bucket 由 BucketName-Appid 组成
17+
# secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
18+
# secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
19+
20+
secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
21+
secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
22+
region = 'ap-chongqing' # 替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
23+
# COS支持的所有region列表参见https://www.qcloud.com/document/product/436/6224
24+
token = None # 如果使用永久密钥不需要填入token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048
25+
26+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme='https') # 获取配置对象
27+
client = CosS3Client(config)
28+
29+
30+
bucket_name = 'demo-1253960454'
31+
32+
33+
def ci_get_file_hash():
34+
response = client.file_hash(Bucket=bucket_name, Key="mytest.mp4", Type='md5')
35+
print(response)
36+
return response
37+
38+
39+
def ci_create_file_hash_job():
40+
body = {
41+
'Type': 'MD5',
42+
}
43+
response = client.ci_create_file_hash_job(
44+
Bucket=bucket_name,
45+
InputObject="mytest.mp4",
46+
FileHashCodeConfig=body
47+
)
48+
print(response)
49+
return response
50+
51+
52+
def ci_create_file_uncompress_job():
53+
body = {
54+
'Prefix': 'output/',
55+
}
56+
response = client.ci_create_file_uncompress_job(
57+
Bucket=bucket_name,
58+
InputObject='test.zip',
59+
FileUncompressConfig=body
60+
)
61+
print(response)
62+
return response
63+
64+
65+
def ci_create_file_compress_job():
66+
body = {
67+
'Flatten': '0',
68+
'Format': 'zip',
69+
'Prefix': '/',
70+
}
71+
response = client.ci_create_file_compress_job(
72+
Bucket=bucket_name,
73+
OutputBucket=bucket_name,
74+
OutputRegion='ap-guangzhou',
75+
OutputObject='result.zip',
76+
FileCompressConfig=body,
77+
CallBack="http://www.callback.com",
78+
CallBackType="Url",
79+
CallBackFormat="XML",
80+
UserData="my data"
81+
)
82+
print(response)
83+
return response
84+
85+
86+
def ci_get_file_process_jobs():
87+
response = client.ci_get_file_process_jobs(
88+
Bucket=bucket_name,
89+
JobIDs='fcb9a9f90e57611ed9************',
90+
)
91+
print(response)
92+
return response
93+
94+
95+
def ci_get_zip_preview():
96+
response = client.ci_file_zip_preview(Bucket=bucket_name, Key="result.zip")
97+
print(response)
98+
return response
99+
100+
101+
if __name__ == '__main__':
102+
# ci_get_file_hash()
103+
# ci_create_file_hash_job()
104+
# ci_create_file_uncompress_job()
105+
# ci_create_file_compress_job()
106+
# ci_get_zip_preview()
107+
ci_get_file_process_jobs()

0 commit comments

Comments
 (0)