Skip to content

Commit 951e683

Browse files
committed
MD5 check support both unicode and bytes
1 parent a637f62 commit 951e683

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

qcloud_cos/cos_client.py

-2
Original file line numberDiff line numberDiff line change
@@ -2266,8 +2266,6 @@ def upload_file(self, Bucket, Key, LocalFilePath, PartSize=1, MAXThread=5, Enabl
22662266
LocalFilePath=file_name,
22672267
PartSize=10,
22682268
MAXThread=10,
2269-
CacheControl='no-cache',
2270-
ContentDisposition='download.txt'
22712269
)
22722270
"""
22732271
file_size = os.path.getsize(LocalFilePath)

qcloud_cos/cos_comm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_md5(data):
9898

9999
def get_content_md5(body):
100100
"""计算任何输入流的md5值"""
101-
if isinstance(body, string_types):
101+
if isinstance(body, text_type) or isinstance(body, binary_type):
102102
return get_md5(body)
103103
elif hasattr(body, 'tell') and hasattr(body, 'seek') and hasattr(body, 'read'):
104104
file_position = body.tell() # 记录文件当前位置
@@ -359,7 +359,7 @@ def get_file_like_object_length(data):
359359
def check_object_content_length(data):
360360
"""put_object接口和upload_part接口的文件大小不允许超过5G"""
361361
content_len = 0
362-
if type(data) is string_types:
362+
if isinstance(data, text_type) or isinstance(data, binary_type):
363363
content_len = len(to_bytes(data))
364364
elif hasattr(data, 'fileno') and hasattr(data, 'tell'):
365365
content_len = get_file_like_object_length(data)

ut/test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ def test_upload_file_multithreading():
651651
Key=file_name,
652652
LocalFilePath=file_name,
653653
MAXThread=10,
654-
CacheControl='no-cache',
655-
ContentDisposition='download.txt'
654+
EnableMD5=True
656655
)
657656
ed = time.time() # 记录结束时间
658657
if os.path.exists(file_name):

0 commit comments

Comments
 (0)