Skip to content

Commit 9bd5e62

Browse files
author
erichmzhang
committed
Support uploading file name that contains Chinese or special character
1 parent 29eff6c commit 9bd5e62

File tree

14 files changed

+148
-72
lines changed

14 files changed

+148
-72
lines changed

QCloudCOSXML.podspec

Lines changed: 2 additions & 2 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.0.2"
3+
s.version = "5.0.3"
44
s.summary = "QCloudCOSXML 腾讯云iOS-SDK组件"
55

66
s.homepage = "https://cloud.tencent.com/"
@@ -9,5 +9,5 @@ Pod::Spec.new do |s|
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.0.2'
12+
s.dependency 'QCloudCore','5.0.3'
1313
end

QCloudCOSXML/Classes/QCloudCOSXMLEndPoint.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@
1212

1313
@interface QCloudCOSXMLEndPoint : QCloudEndPoint
1414
/**
15-
服务地域名称, 目前可用的服务地域名称有:
16-
*.ap-beijing-1 北京一区(华北)
17-
*.ap-beijing 北京
18-
*.ap-shanghai 上海(华东)
19-
*.ap-guangzhou 广州(华南)
20-
*.ap-guangzhou-2 广州(视频云)
21-
*.ap-chengdu 成都(西南)
22-
*.ap-singapore 新加坡
23-
*.ap-hongkong 香港
24-
*.na-toronto 多伦多
25-
*.eu-frankfurt 法兰克福
26-
*.cn-north 华北
15+
服务地域名称,可用的服务地域名称请查看官网https://www.qcloud.com/document/product/436/6224中提供的地域,这里填入官网里提供的地域简称,例如ap-beijing-1等。
2716
*/
2817
@property (nonatomic, copy) QCloudRegion regionName;
2918

QCloudCOSXML/Classes/QCloudCOSXMLEndPoint.m

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,31 @@ - (instancetype) init
2020
return self;
2121
}
2222

23+
- (NSString*)formattedRegionName:(NSString*)regionName {
24+
NSArray* oldRegionNameArray = @[@"cn-east",@"cn-south",@"cn-south-2",@"cn-north",@"cn-southwest",@"sg"];
25+
BOOL isOldRegion = NO;
26+
for (NSString* oldRegionName in oldRegionNameArray) {
27+
if ([regionName isEqualToString:oldRegionName]) {
28+
isOldRegion = YES;
29+
break;
30+
}
31+
}
32+
if (isOldRegion) {
33+
return regionName;
34+
} else {
35+
return [NSString stringWithFormat:@"cos.%@",self.regionName];
36+
}
37+
}
38+
39+
40+
2341
- (NSURL*) serverURLWithBucket:(NSString *)bucket appID:(NSString *)appID
2442
{
2543
NSString* scheme = @"https";
2644
if (!self.useHTTPS) {
2745
scheme = @"http";
2846
}
29-
return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@-%@.cos.%@.%@",scheme,bucket,appID,self.regionName,self.serviceName]];
47+
NSURL* serverURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@-%@.%@.%@",scheme,bucket,appID,[self formattedRegionName:self.regionName],self.serviceName]];
48+
return serverURL;
3049
}
3150
@end

QCloudCOSXML/Classes/QCloudCOSXMLUploadObjectRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef NSData* QCloudCOSXMLUploadObjectResumeData;
1717
@interface QCloudCOSXMLUploadObjectRequest<BodyType> : QCloudAbstractRequest
1818

1919
/**
20-
上传文件(对象)的文件名,也是对象的key
20+
上传文件(对象)的文件名,也是对象的key,请注意文件名中不可以含有问号即"?"字符
2121
*/
2222
@property (strong, nonatomic) NSString *object;
2323

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//
32
// ██████╗ ██████╗██╗ ██████╗ ██╗ ██╗██████╗ ████████╗███████╗██████╗ ███╗ ███╗██╗███╗ ██╗ █████╗ ██╗ ██╗ █████╗ ██████╗
43
// ██╔═══██╗██╔════╝██║ ██╔═══██╗██║ ██║██╔══██╗ ╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗██║ ██║ ██╔══██╗██╔══██╗
@@ -11,9 +10,9 @@
1110
// _ __ _ _
1211
// (_) / _| | | | |
1312
// ___ ___ _ ____ ___ ___ ___ | |_ ___ _ __ __| | _____ _____| | ___ _ __ ___ _ __ ___
14-
// / __|/ _ \ '__\ \ / / |/ __/ _ \ | _/ _ \| '__| / _` |/ _ \ \ / / _ \ |/ _ \| '_ \ / _ \ '__/ __|
15-
// \__ \ __/ | \ V /| | (_| __/ | || (_) | | | (_| | __/\ V / __/ | (_) | |_) | __/ | \__
16-
// |___/\___|_| \_/ |_|\___\___| |_| \___/|_| \__,_|\___| \_/ \___|_|\___/| .__/ \___|_| |___/
13+
// / __|/ _ \\ '__\\ \\ / / |/ __/ _ \\ | _/ _ \\| '__| / _` |/ _ \\ \\ / / _ \\ |/ _ \\| '_ \\ / _ \\ '__/ __|
14+
// \\__ \\ __/ | \\ V /| | (_| __/ | || (_) | | | (_| | __/\\ V / __/ | (_) | |_) | __/ | \\__
15+
// |___/\\___|_| \\_/ |_|\\___\\___| |_| \\___/|_| \\__,_|\\___| \\_/ \\___|_|\\___/| .__/ \\___|_| |___/
1716
// ______ ______ ______ ______ ______ ______ ______ ______ | |
1817
// |______|______|______|______|______|______|______|______| |_|
1918
//
@@ -22,14 +21,15 @@
2221

2322
#ifndef QCloudCOSXMLModuleVersion_h
2423
#define QCloudCOSXMLModuleVersion_h
25-
#define QCloudCOSXMLModuleVersionNumber 1000
26-
FOUNDATION_EXTERN NSString * const QCloudCOSXMLModuleVersion;
27-
FOUNDATION_EXTERN NSString * const QCloudCOSXMLModuleName;
24+
#define QCloudCOSXMLModuleVersionNumber 500003
2825

26+
//dependency
2927

30-
#if QCloudCoreModuleVersionNumber < 1000
31-
#error "库QCloudCOSXML依赖QCloudCore最小版本号为0.1.0,当前引入的QCloudCore版本号过低,请及时升级后使用"
28+
#if (QCloudCoreModuleVersionNumber<500003)
29+
#error "库QCloudCOSXML依赖QCloudCore最小版本号为5.0.3,当前引入的QCloudCore版本号过低,请及时升级后使用"
3230
#endif
33-
31+
//
32+
FOUNDATION_EXTERN NSString * const QCloudCOSXMLModuleVersion;
33+
FOUNDATION_EXTERN NSString * const QCloudCOSXMLModuleName;
34+
3435
#endif
35-

QCloudCOSXML/Classes/QCloudCOSXMLVersion.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
#import "QCloudCOSXMLVersion.h"
32
#import "QCloudCore.h"
4-
NSString * const QCloudCOSXMLModuleVersion = @"5.0.0";
3+
NSString * const QCloudCOSXMLModuleVersion = @"5.0.3";
54
NSString * const QCloudCOSXMLModuleName = @"QCloudCOSXML";
65
@interface QCloudQCloudCOSXMLLoad : NSObject
76
@end
@@ -15,4 +14,3 @@ + (void) load
1514
[[QCloudSDKModuleManager shareInstance] registerModule:module];
1615
}
1716
@end
18-

QCloudCOSXML/README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
您可以通过cocoapods或者下载打包好的动态库的方式来集成SDK。在这里我们推荐您使用cocoapods的方式来进行导入。
2121
##### 使用Cocoapods导入(推荐)
2222

23-
在Podfile文件中使用(我们建议您在使用时指定具体的版本号)
23+
在Podfile文件中使用:
2424

2525
~~~
26-
pod 'QCloudCOSXML','5.0.1'
26+
pod 'QCloudCOSXML'
2727
~~~
2828

2929
##### 使用打包好的动态库导入
@@ -101,13 +101,16 @@ pod 'QCloudCOSXML','5.0.1'
101101

102102
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
103103
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];
104-
configuration.appID = @"1234567";
105-
configuration.signatureProvider = self;
106-
configuration.regionName = @"ap-guangzhou";//填入园区名字,具体的园区可见代码注释
107-
configuration.endPoint = [[QCloudEndPoint alloc] initWithRegionType:currentRegion serviceType:QCloudServiceCOSXML useSSL:NO];
108-
[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];
109-
[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
110-
return YES
104+
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];
105+
configuration.appID = @"*****";
106+
configuration.signatureProvider = self;
107+
QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] init];
108+
endpoint.regionName = @"ap-beijing";//服务地域名称,可用的地域请参考注释
109+
configuration.endpoint = endpoint;
110+
111+
[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];
112+
[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
113+
111114
}
112115

113116
```
@@ -123,14 +126,15 @@ pod 'QCloudCOSXML','5.0.1'
123126
```objective-c
124127
//AppDelegate.m
125128
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
126-
127-
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];
128-
configuration.appID = @"1234567";
129-
configuration.signatureProvider = self;
130-
configuration.regionType = QCloudRegionCNNorth;
131-
configuration.endPoint = [[QCloudEndPoint alloc] initWithRegionType:currentRegion serviceType:QCloudServiceCOSXML useSSL:NO];
132-
[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];
133-
[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
129+
QCloudServiceConfiguration* configuration = [QCloudServiceConfiguration new];
130+
configuration.appID = @"*****";
131+
configuration.signatureProvider = self;
132+
QCloudCOSXMLEndPoint* endpoint = [[QCloudCOSXMLEndPoint alloc] init];
133+
endpoint.regionName = @"ap-beijing";//服务地域名称,可用的地域请参考注释
134+
configuration.endpoint = endpoint;
135+
136+
[QCloudCOSXMLService registerDefaultCOSXMLWithConfiguration:configuration];
137+
[QCloudCOSTransferMangerService registerDefaultCOSTransferMangerWithConfiguration:configuration];
134138
}
135139
```
136140

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.0.2"
11+
s.version = "5.0.3"
1212
s.summary = "QCloudCore--腾讯云iOS-SDK Foundation"
1313

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

QCloudCore/Classes/Logger/QCloudLogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ QCloudLogError( @"Caught \"%@\" with reason \"%@\"%@", \
3333
exception.name, exception, \
3434
[exception callStackSymbols] ? [NSString stringWithFormat:@":\n%@.", [exception callStackSymbols]] : @"")
3535

36+
#define QCloudLogTrance()\
37+
QCloudLog(QCloudLogLevelDebug,@"%@",[NSThread callStackSymbols])
3638
@interface QCloudLogger : NSObject
3739

3840

QCloudCore/Classes/QCLOUDRestNet/CoreRequest/Serializer/QCloudRequestSerializer.m

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "QCloudXMLDictionary.h"
2121
#import "QCloudEncryt.h"
2222
#import "QCloudFileOffsetBody.h"
23+
#import "QCloudURLHelper.h"
2324
NSString* const HTTPMethodPOST = @"POST";
2425
NSString* const HTTPMethodGET = @"GET";
2526
NSString* const HTTPHeaderHOST = @"HOST";
@@ -231,20 +232,31 @@
231232
};
232233

233234

235+
NSString* QCloudURLFuseAllPathComponents(NSArray* componets)
236+
{
237+
NSString* path = @"";
238+
for (NSString* com in componets) {
239+
if (com.length > 0) {
240+
path = QCloudPathJoin(path, com);
241+
}
242+
}
243+
path = QCloudPercentEscapedStringFromString(path);
244+
return path;
245+
}
234246

235247
QCloudRequestSerializerBlock QCloudURLFuseSimple = ^(NSMutableURLRequest* request, QCloudRequestData* data, NSError* __autoreleasing*error) {
236-
NSString* path = QCloudPathJoin(data.serverURL, data.URIMethod);
248+
NSMutableArray* coms = [NSMutableArray new];
249+
if(data.URIMethod.length) {
250+
[coms addObject:data.URIMethod];
251+
}
237252
if (data.URIComponents.count) {
238-
for(int i = 0; i < data.URIComponents.count; i++) {
239-
NSString* component = data.URIComponents[i];
240-
if (component.length > 0) {
241-
path = QCloudPathJoin(path, component);
242-
}
243-
}
253+
[coms addObjectsFromArray:data.URIComponents];
244254
}
255+
NSString* path = QCloudURLFuseAllPathComponents(coms);
256+
path = QCloudPathJoin(data.serverURL, path);
245257
NSURL* url = [NSURL URLWithString:path];
246258
if (nil == url) {
247-
url = [NSURL URLWithString:QCloudEncodeURL(path)];
259+
url = [NSURL URLWithString:QCloudURLEncodeUTF8(path)];
248260
}
249261
NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
250262
return urlRequest;
@@ -297,20 +309,20 @@
297309

298310

299311
QCloudRequestSerializerBlock QCloudURLFuseURIMethodASURLParamters = ^(NSMutableURLRequest* request, QCloudRequestData* data, NSError* __autoreleasing*error) {
312+
300313
NSString* urlStr = nil;
301314
if (request.URL.absoluteString.length > 0) {
302315
urlStr = request.URL.absoluteString;
303316
} else {
304317
urlStr = data.serverURL;
318+
NSMutableArray* coms = [NSMutableArray new];
305319
if (data.URIComponents.count) {
306-
for(int i = 0; i < data.URIComponents.count; i++) {
307-
NSString* component = data.URIComponents[i];
308-
if (component.length > 0) {
309-
urlStr = QCloudPathJoin(urlStr, component);
310-
}
311-
}
320+
[coms addObjectsFromArray:data.URIComponents];
312321
}
322+
NSString* path = QCloudURLFuseAllPathComponents(coms);
323+
urlStr = QCloudPathJoin(urlStr, path);
313324
}
325+
314326
NSMutableDictionary* methodParamters = [NSMutableDictionary new];
315327
if (data.URIMethod) {
316328
methodParamters[data.URIMethod] = @"";

0 commit comments

Comments
 (0)