Skip to content

Commit dfccbe4

Browse files
committed
Merge pull request #76 from qiniu/develop
Release 6.2.8
2 parents d1dcd80 + 6a8e208 commit dfccbe4

File tree

7 files changed

+77
-45
lines changed

7 files changed

+77
-45
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
## CHANGE LOG
22

3+
### v6.2.8
4+
5+
- [#74] fop url escape
6+
- [#75] 统一user agent 格式
7+
8+
### v6.2.7
9+
10+
- [#63] 添加额外错误信息
11+
- [#64] mkfile 支持 key 为 nil
12+
- [#65] 修正 传入的blockComplete在第一次运行的退出时被释放,如果失败重试会变成nil,导致出错
13+
- [#70] 修改上传域名为upload.qiniu.com
14+
- [#72] operation.responseObject 返回增加nil 判断
15+
16+
### v6.2.6
17+
18+
- [#61] 错误信息增加reqid
19+
20+
### v6.2.5
21+
22+
- [#50] update AFN 2.2.3
23+
- [#52] bugfix: 701 retry
24+
325
### v6.2.2
426

527
2014-04-09 issue [#44](https://github.com/qiniu/ios-sdk/pull/44)

QiniuSDK/QiniuConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
#define kQiniuUpHost @"http://upload.qiniu.com"
1111

1212
#define kQiniuUndefinedKey @"?"
13-
#define kQiniuUserAgent @"qiniu-ios-sdk"
13+
14+
#define kQiniuVersion @"6.2.7"

QiniuSDK/QiniuHttpClient.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import "QiniuHttpClient.h"
1111
#import "QiniuConfig.h"
12+
#import "QiniuUtils.h"
1213

1314
@implementation QiniuHttpClient
1415

@@ -89,7 +90,7 @@ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)theR
8990
failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure{
9091

9192
NSMutableURLRequest *request = (NSMutableURLRequest *)theRequest;
92-
[request addValue:kQiniuUserAgent forHTTPHeaderField:@"User-Agent"];
93+
[request addValue:qiniuUserAgent() forHTTPHeaderField:@"User-Agent"];
9394
AFHTTPRequestOperation *operation = [super HTTPRequestOperationWithRequest:request success:success failure:failure];
9495

9596
return operation;
@@ -103,7 +104,7 @@ @implementation QiniuPutExtra
103104
- (NSDictionary *)convertToPostParams{
104105
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.params];
105106
if (self.checkCrc == 1) {
106-
params[@"crc32"] = [NSString stringWithFormat:@"%u", (unsigned int)self.crc32];
107+
params[@"crc32"] = [NSString stringWithFormat:@"%ld", self.crc32];
107108
}
108109
return params;
109110
}

QiniuSDK/QiniuResumableClient.m

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "QiniuResumableClient.h"
1010
#import "QiniuConfig.h"
11+
#import "QiniuUtils.h"
1112

1213
@implementation QiniuResumableClient
1314

@@ -20,11 +21,11 @@ - (QiniuResumableClient *)initWithToken:(NSString *)token
2021
self.token = [[NSString alloc] initWithFormat:@"UpToken %@", token];
2122
self.retryTime = tryTime;
2223
self.chunkSize = chunkSize; // 256k
23-
24+
2425
self.responseSerializer = [AFJSONResponseSerializer serializer];
2526
self.operationQueue = [[NSOperationQueue alloc] init];
2627
[self.operationQueue setMaxConcurrentOperationCount:maxWorkers];
27-
28+
2829
return self;
2930
}
3031

@@ -47,10 +48,10 @@ - (void)mkblock:(NSData *)mappedData
4748
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:callUrl]];
4849

4950
[self setHeaders:request];
50-
51+
5152
NSData *postData = [mappedData subdataWithRange:NSMakeRange(offset, bodyLength)];
5253
[request setHTTPBody:postData];
53-
54+
5455
QNCompleteBlock success = ^(AFHTTPRequestOperation *operation, id responseObject)
5556
{
5657
// TODO: check crc32
@@ -60,7 +61,7 @@ - (void)mkblock:(NSData *)mappedData
6061
{
6162
complete(operation, error);
6263
};
63-
64+
6465
AFHTTPRequestOperation *operation = [super HTTPRequestOperationWithRequest:request
6566
success:success
6667
failure:failure];
@@ -79,12 +80,12 @@ - (void)chunkPut:(NSData *)mappedData
7980
}
8081
NSString *callUrl = [[NSString alloc] initWithFormat:@"%@/bput/%@/%d", blockPutRet.host, blockPutRet.ctx, (unsigned int)blockPutRet.offset];
8182
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:callUrl]];
82-
83+
8384
[self setHeaders:request];
84-
85+
8586
NSData *postData = [mappedData subdataWithRange:NSMakeRange(offsetBase + blockPutRet.offset, bodyLength)];
8687
[request setHTTPBody:postData];
87-
88+
8889
QNCompleteBlock success = ^(AFHTTPRequestOperation *operation, id responseObject)
8990
{
9091
// TODO: check crc32
@@ -94,7 +95,7 @@ - (void)chunkPut:(NSData *)mappedData
9495
{
9596
complete(operation, error);
9697
};
97-
98+
9899
AFHTTPRequestOperation *operation = [super HTTPRequestOperationWithRequest:request
99100
success:success
100101
failure:failure];
@@ -109,21 +110,21 @@ - (void)blockPut:(NSData *)mappedData
109110
complete:(QNCompleteBlock)complete
110111
{
111112
// @autoreleasepool {
112-
113-
113+
114+
114115
UInt32 offsetBase = blockIndex << QiniuBlockBits;
115-
116+
116117
__block UInt32 bodyLength = self.chunkSize < blockSize ? self.chunkSize : blockSize;
117118
__block QiniuBlkputRet *blockPutRet;
118119
__block UInt32 retryTime = self.retryTime;
119120
__block BOOL isMkblock = YES;
120-
121+
121122
QNCompleteBlock __block __weak weakChunkComplete;
122123
QNCompleteBlock chunkComplete;
123124
weakChunkComplete = chunkComplete = ^(AFHTTPRequestOperation *operation, NSError *error)
124125
{
125126
if (error != nil) {
126-
127+
127128
if (retryTime == 0 || isMkblock || [operation.response statusCode] == 701) {
128129
complete(operation, error);
129130
return;
@@ -137,24 +138,24 @@ - (void)blockPut:(NSData *)mappedData
137138
retryTime = self.retryTime;
138139
isMkblock = NO;
139140
blockPutRet = [[QiniuBlkputRet alloc] initWithDictionary:operation.responseObject];
140-
141+
141142
UInt32 remainLength = blockSize - blockPutRet.offset;
142143
bodyLength = self.chunkSize < remainLength ? self.chunkSize : remainLength;
143144
}
144-
145+
145146
if (blockPutRet.offset == blockSize) {
146147
complete(operation, nil);
147148
return;
148149
}
149-
150+
150151
[self chunkPut:mappedData
151152
blockPutRet:blockPutRet
152153
offsetBase:offsetBase
153154
bodyLength:bodyLength
154155
progress:progressBlock
155156
complete:weakChunkComplete];
156157
};
157-
158+
158159
[self mkblock:mappedData
159160
offsetBase:offsetBase
160161
blockSize:blockSize
@@ -167,7 +168,7 @@ - (void)blockPut:(NSData *)mappedData
167168
+ (NSString *)encode:(NSString *)str
168169
{
169170
str = [[str dataUsingEncoding:NSUTF8StringEncoding] base64EncodedStringWithOptions:0];
170-
171+
171172
// is there other methed?
172173
str = [str stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
173174
str = [str stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
@@ -180,31 +181,31 @@ - (void)mkfile:(NSString *)key
180181
progress:(QNProgressBlock)progressBlock
181182
complete:(QNCompleteBlock)complete
182183
{
183-
184+
184185
NSString *mimeStr = extra.mimeType == nil ? @"" : [[NSString alloc] initWithFormat:@"/mimetype/%@", [QiniuResumableClient encode:extra.mimeType]];
185-
186+
186187
NSString *callUrl = [[NSString alloc] initWithFormat:@"%@/mkfile/%u%@", kQiniuUpHost, (unsigned int)fileSize, mimeStr];
187-
188+
188189
if (key != nil) {
189190
NSString *keyStr = [[NSString alloc] initWithFormat:@"/key/%@", [QiniuResumableClient encode:key]];
190191
callUrl = [NSString stringWithFormat:@"%@%@", callUrl, keyStr];
191192
}
192-
193+
193194
if (extra.params != nil) {
194195
NSEnumerator *e = [extra.params keyEnumerator];
195196
for (id key = [e nextObject]; key != nil; key = [e nextObject]) {
196197
callUrl = [NSString stringWithFormat:@"%@/%@/%@", callUrl, key, [QiniuResumableClient encode:[extra.params objectForKey:key]]];
197198
}
198199
}
199-
200+
200201
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:callUrl]];
201202
[self setHeaders:request];
202-
203+
203204
NSMutableData *postData = [NSMutableData data];
204205
NSString *bodyStr = [extra.progresses componentsJoinedByString:@","];
205206
[postData appendData:[bodyStr dataUsingEncoding:NSUTF8StringEncoding]];
206207
[request setHTTPBody:postData];
207-
208+
208209
QNCompleteBlock success = ^(AFHTTPRequestOperation *operation, id responseObject)
209210
{
210211
complete(operation, nil);
@@ -213,7 +214,7 @@ - (void)mkfile:(NSString *)key
213214
{
214215
complete(operation, error);
215216
};
216-
217+
217218
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request
218219
success:success
219220
failure:failure];
@@ -224,7 +225,7 @@ - (void)setHeaders:(NSMutableURLRequest *)request
224225
{
225226
[request setValue:self.token forHTTPHeaderField:@"Authorization"];
226227
[request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
227-
[request addValue:kQiniuUserAgent forHTTPHeaderField:@"User-Agent"];
228+
[request addValue:qiniuUserAgent() forHTTPHeaderField:@"User-Agent"];
228229
[request setHTTPMethod:@"POST"];
229230
}
230231

@@ -263,14 +264,14 @@ - (BOOL) blockUploadedAndCheck
263264
if (blockNumlock == nil) {
264265
blockNumlock = [[NSLock alloc] init];
265266
}
266-
267+
267268
BOOL allBlockOk;
268-
269+
269270
[blockNumlock lock];
270271
self.uploadedBlockNumber ++;
271272
allBlockOk = self.uploadedBlockNumber == self.blockCount;
272273
[blockNumlock unlock];
273-
274+
274275
return allBlockOk;
275276
}
276277

@@ -280,13 +281,13 @@ - (float) chunkUploadedAndPercent
280281
if (chunkNumlock == nil) {
281282
chunkNumlock = [[NSLock alloc] init];
282283
}
283-
284+
284285
float percent;
285286
[chunkNumlock lock];
286287
self.uploadedChunkNumber ++;
287288
percent = (float)self.uploadedChunkNumber / self.chunkCount;
288289
[chunkNumlock unlock];
289-
290+
290291
return percent;
291292
}
292293

QiniuSDK/QiniuSimpleUploader.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#import "QiniuUtils.h"
1111
#import "QiniuHttpClient.h"
1212

13-
#define kQiniuUserAgent @"qiniu-ios-sdk"
14-
1513
@interface QiniuSimpleUploader ()
1614
//@property(nonatomic,copy)NSString *filePath;
1715
//@property(nonatomic,assign)uint64_t *fileSize;
@@ -58,7 +56,7 @@ - (void) uploadFile:(NSString *)filePath
5856
[self.delegate uploadSucceeded:filePath ret:resp];
5957
}
6058
}];
61-
59+
6260
}
6361

6462
@end

QiniuSDK/QiniuUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
NSError *qiniuError(int errorCode, NSString *errorDescription);
1212

1313
NSError *qiniuErrorWithOperation(AFHTTPRequestOperation *operation, NSError *error);
14+
15+
NSString *qiniuUserAgent();

QiniuSDK/QiniuUtils.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// Created by Qiniu Developers 2013
66
//
77

8+
#import <UIKit/UIKit.h>
9+
10+
#import "QiniuConfig.h"
811
#import "QiniuUtils.h"
912

1013
#define kQiniuErrorKey @"error"
@@ -15,25 +18,29 @@
1518
}
1619

1720
NSError *qiniuErrorWithOperation(AFHTTPRequestOperation *operation, NSError *error) {
18-
21+
1922
if (operation == nil || operation.responseObject == nil) {
2023
return error;
2124
}
22-
25+
2326
NSMutableDictionary *userInfo = nil;
2427
NSInteger errorCode = -1;
25-
28+
2629
if ([operation.responseObject isKindOfClass:NSDictionary.class]) {
2730
userInfo = [NSMutableDictionary dictionaryWithDictionary:operation.responseObject];
2831
}
2932
errorCode = [operation.response statusCode];
30-
33+
3134
if (!userInfo) {
3235
userInfo = [NSMutableDictionary init];
3336
}
34-
37+
3538
NSString *reqid = [[operation.response allHeaderFields] objectForKey:@"X-Reqid"];
3639
[userInfo setObject:reqid forKey:@"reqid"];
37-
40+
3841
return [NSError errorWithDomain:kQiniuErrorDomain code:errorCode userInfo:userInfo];
3942
}
43+
44+
NSString *qiniuUserAgent() {
45+
return [NSString stringWithFormat:@"Qiniu-iOS/%@ (%@; iOS %@; )", kQiniuVersion, [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]];
46+
}

0 commit comments

Comments
 (0)