Skip to content

Commit 0088ffe

Browse files
author
lewzylu
committed
Add MD5 check
1 parent bf387dd commit 0088ffe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

qcloud_cos/cos_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import xml.etree.ElementTree
1313
from requests import Request, Session
1414
from urllib import quote
15+
from hashlib import md5
1516
from streambody import StreamBody
1617
from xml2dict import Xml2Dict
1718
from dicttoxml import dicttoxml
@@ -440,6 +441,10 @@ def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, **kwargs):
440441
auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key, Key),
441442
data=Body)
442443
response = dict()
444+
logger.debug("local md5: {key}".format(key=rt.headers['ETag'][1:-1]))
445+
logger.debug("cos md5: {key}".format(key=md5(Body).hexdigest()))
446+
if md5(Body).hexdigest() != rt.headers['ETag'][1:-1]:
447+
raise CosClientError("MD5 inconsistencies")
443448
response['ETag'] = rt.headers['ETag']
444449
return response
445450

0 commit comments

Comments
 (0)