Skip to content

Commit

Permalink
Upload Part Enable MD5 Check
Browse files Browse the repository at this point in the history
  • Loading branch information
dt3310321 committed Apr 3, 2018
1 parent 17e406a commit 638f450
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def create_multipart_upload(self, Bucket, Key, **kwargs):
data = xml_to_dict(rt.text)
return data

def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, **kwargs):
def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, EnableMD5=False, **kwargs):
"""上传分块,单个大小不得超过5GB
:param Bucket(string): 存储桶名称.
Expand All @@ -562,6 +562,7 @@ def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, **kwargs):
:param PartNumber(int): 上传分块的编号.
:param UploadId(string): 分块上传创建的UploadId.
:param kwargs(dict): 设置请求headers.
:param EnableMD5(bool): 是否需要SDK计算Content-MD5,打开此开关会增加上传耗时.
:return(dict): 上传成功返回的结果,包含单个分块ETag等信息.
.. code-block:: python
Expand All @@ -585,6 +586,10 @@ def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, **kwargs):
url=url,
headers=headers))
Body = deal_with_empty_file_stream(Body)
if EnableMD5:
md5_str = get_content_md5(Body)
if md5_str:
headers['Content-MD5'] = md5_str
rt = self.send_request(
method='PUT',
url=url,
Expand Down

0 comments on commit 638f450

Please sign in to comment.