Skip to content

Commit 87072a4

Browse files
author
karisli
committed
# 5.5.2
- 加了校验MD开关
1 parent 1f9a512 commit 87072a4

File tree

11 files changed

+61
-47
lines changed

11 files changed

+61
-47
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 5.5.2
2+
- 加了校验MD开关
3+
14
# 5.5.1
25
-将部分文件与 FCUUID 作区分
36

QCloudCOSXML.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "QCloudCOSXML"
3-
s.version = "5.5.1"
3+
s.version = "5.5.2"
44
s.summary = "QCloudCOSXML 腾讯云iOS-SDK组件"
55

66
s.homepage = "https://cloud.tencent.com/"
@@ -9,12 +9,12 @@ s.version = "5.5.1"
99
s.source = { :git => "https://github.com/tencentyun/qcloud-sdk-ios.git", :tag => s.version.to_s }
1010
s.ios.deployment_target = '8.0'
1111
s.source_files = 'QCloudCOSXML/Classes/**/*'
12-
s.dependency "QCloudCore",'5.5.1'
12+
s.dependency "QCloudCore",'5.5.2'
1313
s.static_framework = true
1414

1515
s.subspec 'Transfer' do |sbt|
1616
sbt.source_files = 'QCloudCOSXML/Classes/Transfer/**/*','QCloudCOSXML/Classes/Base/*'
17-
sbt.dependency "QCloudCore",'5.5.1'
17+
sbt.dependency "QCloudCore",'5.5.2'
1818
# sbt.static_framework=true
1919
end
2020
end

QCloudCOSXML/Classes/QCloudCOSXMLVersion.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
#ifndef QCloudCOSXMLModuleVersion_h
88
#define QCloudCOSXMLModuleVersion_h
9-
#define QCloudCOSXMLModuleVersionNumber 505001
9+
#define QCloudCOSXMLModuleVersionNumber 505002
1010

1111
//dependency
12-
#if QCloudCoreModuleVersionNumber != 505001
12+
#if QCloudCoreModuleVersionNumber != 505002
1313
#error "库QCloudCOSXML依赖QCloudCore最小版本号为5.5.1,当前引入的QCloudCore版本号过低,请及时升级后使用"
1414
#endif
1515

1616
//
1717
FOUNDATION_EXTERN NSString * const QCloudCOSXMLModuleVersion;
1818
FOUNDATION_EXTERN NSString * const QCloudCOSXMLModuleName;
1919

20-
#endif
20+
#endif

QCloudCOSXML/Classes/QCloudCOSXMLVersion.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import "QCloudCOSXMLVersion.h"
2-
NSString * const QCloudCOSXMLModuleVersion = @"5.5.1";
2+
NSString * const QCloudCOSXMLModuleVersion = @"5.5.2";
33
NSString * const QCloudCOSXMLModuleName = @"QCloudCOSXML";
44
@interface QCloudQCloudCOSXMLLoad : NSObject
55
@end
@@ -26,4 +26,4 @@ + (void) load
2626
#pragma clang diagnostic pop
2727
}
2828
}
29-
@end
29+
@end

QCloudCOSXML/Classes/Transfer/QCloudCOSXMLService+Transfer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
#import <Foundation/Foundation.h>
9-
#import "QCLoudCOSXMLService.h"
9+
#import "QCloudCOSXMLService.h"
1010
@class QCloudPutObjectRequest;
1111
@class QCloudGetObjectRequest;
1212
@class QCloudInitiateMultipartUploadRequest;

QCloudCOSXML/Classes/Transfer/request/QCloudCOSXMLUploadObjectRequest.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ typedef void(^InitMultipleUploadFinishBlock)(QCloudInitiateMultipartUploadResult
112112
*/
113113
@property (nonatomic, copy) InitMultipleUploadFinishBlock initMultipleUploadFinishBlock;
114114

115+
116+
/**
117+
是否在上传完成以后,将 COS 返回的文件MD5与本地文件算出来的md5进行校验。默认开启,如果校验出错,文件仍然会被上传到 COS, 不过我们会在本地抛出校验失败的error。
118+
*/
119+
@property (nonatomic, assign) BOOL enableMD5Verification;
120+
115121
/**
116122
上传完成后会通过该block回调。若error为空,可视为成功。
117123

QCloudCOSXML/Classes/Transfer/request/QCloudCOSXMLUploadObjectRequest.m

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ - (instancetype) init
7979
}
8080
_requestCacheArray = [NSPointerArray weakObjectsPointerArray];
8181
_aborted = NO;
82+
_enableMD5Verification = YES;
8283
_recursiveLock = [NSRecursiveLock new];
8384
_progressLock = [NSRecursiveLock new];
8485
return self;
@@ -193,32 +194,33 @@ - (void) startSimpleUpload
193194
if (error) {
194195
[weakSelf onError:error];
195196
[self cancel];
196-
} else {
197+
} else{
197198
QCloudUploadObjectResult* result = [QCloudUploadObjectResult new];
198-
result.eTag = [outputObject valueForKey:@"Etag"];
199199
if (outputObject[@"x-cos-version-id"]) {
200200
result.versionID = outputObject[@"x-cos-version-id"];
201201
}
202202

203-
NSString* localMD5 ;
204-
if ([weakSelf.body isKindOfClass:[NSData class]]) {
205-
localMD5 = QCloudEncrytNSDataMD5(weakSelf.body);
206-
} else if ([weakSelf.body isKindOfClass:[NSURL class]]) {
207-
localMD5 = QCloudEncrytFileMD5(((NSURL*)weakSelf.body).path);
208-
}
209-
NSString* MD5FromCOS = [result.eTag substringWithRange:NSMakeRange(1, result.eTag.length - 2)];
210-
if (![localMD5.lowercaseString isEqualToString:MD5FromCOS]) {
211-
NSMutableString* errorMessageString = [[NSMutableString alloc] init];
212-
[errorMessageString appendFormat:@"简单上传过程中MD5校验与本地不一致,请检查本地文件在上传过程中是否发生了变化,建议调用删除接口将COS上的文件删除并重新上传"];
213-
if ( outputObject[@"x-cos-request-id"]!= nil) {
214-
NSString* requestID = outputObject[@"x-cos-request-id"];
215-
[errorMessageString appendFormat:@", Request id:%@",requestID];
203+
if(self.enableMD5Verification) {
204+
result.eTag = [outputObject valueForKey:@"Etag"];
205+
NSString* localMD5 ;
206+
if ([weakSelf.body isKindOfClass:[NSData class]]) {
207+
localMD5 = QCloudEncrytNSDataMD5(weakSelf.body);
208+
} else if ([weakSelf.body isKindOfClass:[NSURL class]]) {
209+
localMD5 = QCloudEncrytFileMD5(((NSURL*)weakSelf.body).path);
210+
}
211+
NSString* MD5FromCOS = [result.eTag substringWithRange:NSMakeRange(1, result.eTag.length - 2)];
212+
if ( (localMD5 != nil) && (![localMD5.lowercaseString isEqualToString:MD5FromCOS]) ) {
213+
NSMutableString* errorMessageString = [[NSMutableString alloc] init];
214+
[errorMessageString appendFormat:@"简单上传过程中MD5校验与本地不一致,请检查本地文件在上传过程中是否发生了变化,建议调用删除接口将COS上的文件删除并重新上传"];
215+
if ( outputObject[@"x-cos-request-id"]!= nil) {
216+
NSString* requestID = outputObject[@"x-cos-request-id"];
217+
[errorMessageString appendFormat:@", Request id:%@",requestID];
218+
}
219+
NSError* error = [NSError qcloud_errorWithCode:QCloudNetworkErrorCodeMD5NotMatch message:errorMessageString];
220+
[weakSelf onError:error];
221+
return ;
216222
}
217-
NSError* error = [NSError qcloud_errorWithCode:QCloudNetworkErrorCodeMD5NotMatch message:errorMessageString];
218-
[weakSelf onError:error];
219-
return ;
220223
}
221-
222224
result.key = weakSelf.object;
223225
result.bucket = weakSelf.bucket;
224226
result.location = QCloudCOSXMLObjectLocation(weakSelf.transferManager.configuration.endpoint,
@@ -391,24 +393,26 @@ - (void) uploadOffsetBodys:(NSArray<QCloudFileOffsetBody*>*)allParts
391393
if (!self.canceled) {
392394
[strongSelf cancel];
393395
}
394-
} else {
396+
} else{
395397

396-
NSString* MD5FromeETag = [outputObject.eTag substringWithRange:NSMakeRange(1, outputObject.eTag.length-2)];
397-
NSString* localMD5String = [QCloudEncrytFileOffsetMD5(body.fileURL.path, body.offset, body.sliceLength) lowercaseString];
398-
if (![MD5FromeETag isEqualToString:localMD5String]) {
399-
NSMutableString* errorMessageString = [[NSMutableString alloc] init];
400-
[errorMessageString appendFormat:@"分片上传过程中MD5校验与本地不一致,请检查本地文件在上传过程中是否发生了变化,建议调用删除接口将COS上的文件删除并重新上传"];
401-
if ( [outputObject __originHTTPURLResponse__]&& [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"]!= nil) {
402-
NSString* requestID = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"];
403-
[errorMessageString appendFormat:@", Request id:%@",requestID];
398+
if(self.enableMD5Verification) {
399+
400+
NSString* MD5FromeETag = [outputObject.eTag substringWithRange:NSMakeRange(1, outputObject.eTag.length-2)];
401+
NSString* localMD5String = [QCloudEncrytFileOffsetMD5(body.fileURL.path, body.offset, body.sliceLength) lowercaseString];
402+
if (![MD5FromeETag isEqualToString:localMD5String]) {
403+
NSMutableString* errorMessageString = [[NSMutableString alloc] init];
404+
[errorMessageString appendFormat:@"分片上传过程中MD5校验与本地不一致,请检查本地文件在上传过程中是否发生了变化,建议调用删除接口将COS上的文件删除并重新上传"];
405+
if ( [outputObject __originHTTPURLResponse__]&& [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"]!= nil) {
406+
NSString* requestID = [[outputObject __originHTTPURLResponse__].allHeaderFields valueForKey:@"x-cos-request-id"];
407+
[errorMessageString appendFormat:@", Request id:%@",requestID];
408+
}
409+
NSError* error = [NSError qcloud_errorWithCode:QCloudNetworkErrorCodeMD5NotMatch message:errorMessageString];
410+
[weakSelf onError:error];
411+
[weakSelf cancel];
412+
return ;
404413
}
405-
NSError* error = [NSError qcloud_errorWithCode:QCloudNetworkErrorCodeMD5NotMatch message:errorMessageString];
406-
[weakSelf onError:error];
407-
[weakSelf cancel];
408-
return ;
409414
}
410415

411-
412416
QCloudMultipartInfo* info = [QCloudMultipartInfo new];
413417
info.eTag = outputObject.eTag;
414418
info.partNumber = [@(body.index+1) stringValue];

QCloudCore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "QCloudCore"
11-
s.version = "5.5.1"
11+
s.version = "5.5.2"
1212
s.summary = "QCloudCore--腾讯云iOS-SDK Foundation"
1313

1414
# This description is used to generate tags and improve search results.

QCloudCore/Classes/QCloudClientBase/Request/QCloudService.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
1515

1616
@class QCloudHTTPRequest;
1717
@class QCloudSignatureFields;
18+
@class UIApplication;
1819
@interface QCloudService : NSObject
1920
{
2021
@protected

QCloudCore/Classes/QCloudCoreVersion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
#ifndef QCloudCoreModuleVersion_h
77
#define QCloudCoreModuleVersion_h
8-
#define QCloudCoreModuleVersionNumber 505001
8+
#define QCloudCoreModuleVersionNumber 505002
99

1010
//dependency
1111

1212
//
1313
FOUNDATION_EXTERN NSString * const QCloudCoreModuleVersion;
1414
FOUNDATION_EXTERN NSString * const QCloudCoreModuleName;
1515

16-
#endif
16+
#endif

0 commit comments

Comments
 (0)