|
12 | 12 | import xml.etree.ElementTree |
13 | 13 | from requests import Request, Session |
14 | 14 | from urllib import quote |
| 15 | +from hashlib import md5 |
15 | 16 | from streambody import StreamBody |
16 | 17 | from xml2dict import Xml2Dict |
17 | 18 | from dicttoxml import dicttoxml |
@@ -55,7 +56,7 @@ def __init__(self, Appid=None, Region=None, Secret_id=None, Secret_key=None, Tok |
55 | 56 | if Scheme is None: |
56 | 57 | Scheme = 'http' |
57 | 58 | if(Scheme != 'http' and Scheme != 'https'): |
58 | | - raise CosCosClientError('Scheme can be only set to http/https') |
| 59 | + raise CosClientError('Scheme can be only set to http/https') |
59 | 60 | self._scheme = Scheme |
60 | 61 |
|
61 | 62 | # 兼容(SecretId,SecretKey)以及(AccessId,AccessKey) |
@@ -440,6 +441,10 @@ def upload_part(self, Bucket, Key, Body, PartNumber, UploadId, **kwargs): |
440 | 441 | auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key, Key), |
441 | 442 | data=Body) |
442 | 443 | 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") |
443 | 448 | response['ETag'] = rt.headers['ETag'] |
444 | 449 | return response |
445 | 450 |
|
@@ -1311,7 +1316,7 @@ def copy(self, Bucket, Key, CopySource, CopyStatus='Copy', PartSize=10, MAXThrea |
1311 | 1316 | abort_response = self.abort_multipart_upload(Bucket=Bucket, Key=Key, UploadId=uploadid) |
1312 | 1317 | raise e |
1313 | 1318 | return rt |
1314 | | - |
| 1319 | + |
1315 | 1320 | def append_object(self, Bucket, Key, Position, Data, **kwargs): |
1316 | 1321 | """文件块追加接口 |
1317 | 1322 |
|
@@ -1341,7 +1346,7 @@ def append_object(self, Bucket, Key, Position, Data, **kwargs): |
1341 | 1346 | headers=headers) |
1342 | 1347 | response = rt.headers |
1343 | 1348 | return response |
1344 | | - |
1345 | | - |
| 1349 | + |
| 1350 | + |
1346 | 1351 | if __name__ == "__main__": |
1347 | 1352 | pass |
0 commit comments