Skip to content

Commit

Permalink
Merge pull request #36 from lewzylu/add-md5-check
Browse files Browse the repository at this point in the history
Add md5 check
  • Loading branch information
dt3310321 authored Jan 16, 2018
2 parents 88045a4 + cd08435 commit 4baeb43
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import xml.etree.ElementTree
from requests import Request, Session
from urllib import quote
from hashlib import md5
from streambody import StreamBody
from xml2dict import Xml2Dict
from dicttoxml import dicttoxml
Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(self, Appid=None, Region=None, Secret_id=None, Secret_key=None, Tok
if Scheme is None:
Scheme = 'http'
if(Scheme != 'http' and Scheme != 'https'):
raise CosCosClientError('Scheme can be only set to http/https')
raise CosClientError('Scheme can be only set to http/https')
self._scheme = Scheme

# 兼容(SecretId,SecretKey)以及(AccessId,AccessKey)
Expand Down Expand Up @@ -440,6 +441,10 @@ def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, **kwargs):
auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key, Key),
data=Body)
response = dict()
logger.debug("local md5: {key}".format(key=rt.headers['ETag'][1:-1]))
logger.debug("cos md5: {key}".format(key=md5(Body).hexdigest()))
if md5(Body).hexdigest() != rt.headers['ETag'][1:-1]:
raise CosClientError("MD5 inconsistencies")
response['ETag'] = rt.headers['ETag']
return response

Expand Down Expand Up @@ -1311,7 +1316,7 @@ def copy(self, Bucket, Key, CopySource, CopyStatus='Copy', PartSize=10, MAXThrea
abort_response = self.abort_multipart_upload(Bucket=Bucket, Key=Key, UploadId=uploadid)
raise e
return rt

def append_object(self, Bucket, Key, Position, Data, **kwargs):
"""文件块追加接口
Expand Down Expand Up @@ -1341,7 +1346,7 @@ def append_object(self, Bucket, Key, Position, Data, **kwargs):
headers=headers)
response = rt.headers
return response


if __name__ == "__main__":
pass

0 comments on commit 4baeb43

Please sign in to comment.