From 951e6832aac810e71680ba78b2c1ee5bcbe4b20c Mon Sep 17 00:00:00 2001 From: tiedu Date: Tue, 14 May 2019 13:24:22 +0800 Subject: [PATCH 1/2] MD5 check support both unicode and bytes --- qcloud_cos/cos_client.py | 2 -- qcloud_cos/cos_comm.py | 4 ++-- ut/test.py | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/qcloud_cos/cos_client.py b/qcloud_cos/cos_client.py index cdb30e15..05de4adf 100644 --- a/qcloud_cos/cos_client.py +++ b/qcloud_cos/cos_client.py @@ -2266,8 +2266,6 @@ def upload_file(self, Bucket, Key, LocalFilePath, PartSize=1, MAXThread=5, Enabl LocalFilePath=file_name, PartSize=10, MAXThread=10, - CacheControl='no-cache', - ContentDisposition='download.txt' ) """ file_size = os.path.getsize(LocalFilePath) diff --git a/qcloud_cos/cos_comm.py b/qcloud_cos/cos_comm.py index 388730e7..6e48353b 100644 --- a/qcloud_cos/cos_comm.py +++ b/qcloud_cos/cos_comm.py @@ -98,7 +98,7 @@ def get_md5(data): def get_content_md5(body): """计算任何输入流的md5值""" - if isinstance(body, string_types): + if isinstance(body, text_type) or isinstance(body, binary_type): return get_md5(body) elif hasattr(body, 'tell') and hasattr(body, 'seek') and hasattr(body, 'read'): file_position = body.tell() # 记录文件当前位置 @@ -359,7 +359,7 @@ def get_file_like_object_length(data): def check_object_content_length(data): """put_object接口和upload_part接口的文件大小不允许超过5G""" content_len = 0 - if type(data) is string_types: + if isinstance(data, text_type) or isinstance(data, binary_type): content_len = len(to_bytes(data)) elif hasattr(data, 'fileno') and hasattr(data, 'tell'): content_len = get_file_like_object_length(data) diff --git a/ut/test.py b/ut/test.py index 241be7b4..47f69639 100644 --- a/ut/test.py +++ b/ut/test.py @@ -651,8 +651,7 @@ def test_upload_file_multithreading(): Key=file_name, LocalFilePath=file_name, MAXThread=10, - CacheControl='no-cache', - ContentDisposition='download.txt' + EnableMD5=True ) ed = time.time() # 记录结束时间 if os.path.exists(file_name): From df14224bffd54aa5db2cff0082158967ed84cc6c Mon Sep 17 00:00:00 2001 From: tiedu Date: Tue, 14 May 2019 13:28:37 +0800 Subject: [PATCH 2/2] fix newline --- qcloud_cos/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcloud_cos/version.py b/qcloud_cos/version.py index f975ef2a..5671e3a5 100644 --- a/qcloud_cos/version.py +++ b/qcloud_cos/version.py @@ -1,2 +1,2 @@ -__version__ = '5.1.6.7' \ No newline at end of file +__version__ = '5.1.6.7'