|
31 | 31 | #import <QCloudCore/QCloudHTTPRetryHanlder.h> |
32 | 32 | static NSUInteger kQCloudCOSXMLUploadLengthLimit = 1*1024*1024; |
33 | 33 | static NSUInteger kQCloudCOSXMLUploadSliceLength = 1*1024*1024; |
34 | | - |
| 34 | +static NSUInteger kQCloudCOSXMLMD5Length = 32; |
| 35 | +static NSUInteger kQCloudCOSXMLSha1Length = 40; |
35 | 36 | @interface QCloudCOSXMlResumeUploadInfo : NSObject |
36 | 37 | @property (nonatomic, strong) NSString* localPath; |
37 | 38 | @property (strong, nonatomic) NSString *object; |
@@ -497,25 +498,26 @@ - (void) uploadOffsetBodys:(NSArray<QCloudFileOffsetBody*>*)allParts |
497 | 498 | [strongSelf cancel]; |
498 | 499 | } |
499 | 500 | } else{ |
500 | | - |
501 | | - if(self.enableMD5Verification) { |
502 | | - |
503 | | - NSString* MD5FromeETag = [outputObject.eTag substringWithRange:NSMakeRange(1, outputObject.eTag.length-2)]; |
504 | | - NSString* localMD5String = [QCloudEncrytFileOffsetMD5(body.fileURL.path, body.offset, body.sliceLength) lowercaseString]; |
505 | | - if (![MD5FromeETag isEqualToString:localMD5String]) { |
506 | | - NSMutableString* errorMessageString = [[NSMutableString alloc] init]; |
507 | | - [errorMessageString appendFormat:@"DataIntegrityError分片:上传过程中MD5校验与本地不一致,请检查本地文件在上传过程中是否发生了变化,建议调用删除接口将COS上的文件删除并重新上传,本地计算的 MD5 值:%@, 返回的 ETag值:%@",localMD5String,MD5FromeETag]; |
508 | | - if ( [outputObject __originHTTPURLResponse__]&& [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"]!= nil) { |
509 | | - NSString* requestID = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"]; |
510 | | - [errorMessageString appendFormat:@", Request id:%@",requestID]; |
| 501 | + if (self.enableMD5Verification || self.enableVerification) { |
| 502 | + if(outputObject.eTag.length == (kQCloudCOSXMLMD5Length+2)) { |
| 503 | + NSString* MD5FromeETag = [outputObject.eTag substringWithRange:NSMakeRange(1, outputObject.eTag.length-2)]; |
| 504 | + NSString* localMD5String = [QCloudEncrytFileOffsetMD5(body.fileURL.path, body.offset, body.sliceLength) lowercaseString]; |
| 505 | + if (![MD5FromeETag isEqualToString:localMD5String]) { |
| 506 | + NSMutableString* errorMessageString = [[NSMutableString alloc] init]; |
| 507 | + [errorMessageString appendFormat:@"DataIntegrityError分片:上传过程中MD5校验与本地不一致,请检查本地文件在上传过程中是否发生了变化,建议调用删除接口将COS上的文件删除并重新上传,本地计算的 MD5 值:%@, 返回的 ETag值:%@",localMD5String,MD5FromeETag]; |
| 508 | + if ( [outputObject __originHTTPURLResponse__]&& [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"]!= nil) { |
| 509 | + NSString* requestID = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"]; |
| 510 | + [errorMessageString appendFormat:@", Request id:%@",requestID]; |
| 511 | + } |
| 512 | + NSError* error = [NSError qcloud_errorWithCode:QCloudNetworkErrorCodeMD5NotMatch message:errorMessageString]; |
| 513 | + [weakSelf onError:error]; |
| 514 | + [weakSelf cancel]; |
| 515 | + return ; |
511 | 516 | } |
512 | | - NSError* error = [NSError qcloud_errorWithCode:QCloudNetworkErrorCodeMD5NotMatch message:errorMessageString]; |
513 | | - [weakSelf onError:error]; |
514 | | - [weakSelf cancel]; |
515 | | - return ; |
516 | 517 | } |
517 | 518 | } |
518 | 519 |
|
| 520 | + |
519 | 521 | QCloudMultipartInfo* info = [QCloudMultipartInfo new]; |
520 | 522 | info.eTag = outputObject.eTag; |
521 | 523 | info.partNumber = [@(body.index+1) stringValue]; |
|
0 commit comments