Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Categories/NSString+Qiniu.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@ @implementation NSString (Qiniu)

- (NSString *)qnImageInfo
{
return [NSString stringWithFormat:@"%@?imageInfo", self];
return [[NSString stringWithFormat:@"%@?imageInfo", self] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnEXIF
{
return [NSString stringWithFormat:@"%@?exif", self];
return [[NSString stringWithFormat:@"%@?exif", self] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnScaleToPercent:(CGFloat)percent
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/!%fp", self, percent];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/!%fp", self, percent] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnScaleFitWidth:(CGFloat)width
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%f", self, width];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%f", self, width] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnScaleFitHeight:(CGFloat)height
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/x%f", self, height];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/x%f", self, height] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnScaleAspectFit:(CGSize)size
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%fx%f", self, size.width, size.height];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%fx%f", self, size.width, size.height] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnScaleAspectFill:(CGSize)size
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%fx%f^", self, size.width, size.height];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%fx%f^", self, size.width, size.height] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnScaleToFill:(CGSize)size
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%fx%f!", self, size.width, size.height];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/thumbnail/%fx%f!", self, size.width, size.height] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

- (NSString *)qnCropFromCenterToSize:(CGSize)size
{
return [NSString stringWithFormat:@"%@?imageMogr/v2/gravity/center/crop/!%fx%f", self, size.width, size.height];
return [[NSString stringWithFormat:@"%@?imageMogr/v2/gravity/center/crop/!%fx%f", self, size.width, size.height] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

@end
118 changes: 59 additions & 59 deletions QiniuDemo/QiniuDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
BAB59D3818B8EE7400F235AA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = Qiniu;
};
buildConfigurationList = BAB59D3B18B8EE7400F235AA /* Build configuration list for PBXProject "QiniuSDK" */;
Expand Down Expand Up @@ -362,7 +362,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -400,7 +399,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -463,7 +461,6 @@
BAB59D6718B8EE7400F235AA /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -484,7 +481,6 @@
BAB59D6818B8EE7400F235AA /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0500"
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/QiniuConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import <Foundation/Foundation.h>

#define kQiniuUpHost @"http://up.qiniu.com"
#define kQiniuUpHost @"http://upload.qiniu.com"

#define kQiniuUndefinedKey @"?"
#define kQiniuUserAgent @"qiniu-ios-sdk"
2 changes: 1 addition & 1 deletion QiniuSDK/QiniuResumableClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef void (^QiniuRioNotifyErr)(int blockIndex, int blockSize, NSError* error)



@interface QiniuRioPutExtra : NSObject
@interface QiniuRioPutExtra : NSObject<NSCoding>

+ (QiniuRioPutExtra *)extraWithParams:(NSDictionary *)params;
- (QiniuRioPutExtra *)init;
Expand Down
34 changes: 32 additions & 2 deletions QiniuSDK/QiniuResumableClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,13 @@ - (void)mkfile:(NSString *)key
{

NSString *mimeStr = extra.mimeType == nil ? @"" : [[NSString alloc] initWithFormat:@"/mimetype/%@", [QiniuResumableClient encode:extra.mimeType]];
NSString *keyStr = [[NSString alloc] initWithFormat:@"/key/%@", [QiniuResumableClient encode:key]];
NSString *callUrl = [[NSString alloc] initWithFormat:@"%@/mkfile/%u%@%@", kQiniuUpHost, (unsigned int)fileSize, mimeStr, keyStr];

NSString *callUrl = [[NSString alloc] initWithFormat:@"%@/mkfile/%u%@", kQiniuUpHost, (unsigned int)fileSize, mimeStr];

if (key != nil) {
NSString *keyStr = [[NSString alloc] initWithFormat:@"/key/%@", [QiniuResumableClient encode:key]];
callUrl = [NSString stringWithFormat:@"%@%@", callUrl, keyStr];
}

if (extra.params != nil) {
NSEnumerator *e = [extra.params keyEnumerator];
Expand Down Expand Up @@ -285,4 +290,29 @@ - (float) chunkUploadedAndPercent
return percent;
}

- (void) encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.params forKey:@"params"];
[aCoder encodeObject:self.mimeType forKey:@"mimeType"];
[aCoder encodeInt32:self.chunkSize forKey:@"chunkSize"];
[aCoder encodeInt32:self.tryTimes forKey:@"tryTimes"];
[aCoder encodeInt32:self.concurrentNum forKey:@"concurrentNum"];
[aCoder encodeObject:self.progresses forKey:@"progresses"];
[aCoder encodeInt32:self.blockCount forKey:@"blockCount"];
[aCoder encodeInt32:self.chunkCount forKey:@"chunkCount"];
}

- (id) initWithCoder:(NSCoder *)aDecoder {
if (self = [super init]) {
self.params = [aDecoder decodeObjectForKey:@"params"];
self.mimeType = [aDecoder decodeObjectForKey:@"mimeType"];
self.chunkSize = [aDecoder decodeInt32ForKey:@"chunkSize"];
self.tryTimes = [aDecoder decodeInt32ForKey:@"tryTimes"];
self.concurrentNum = [aDecoder decodeInt32ForKey:@"concurrentNum"];
self.progresses = [aDecoder decodeObjectForKey:@"progresses"];
self.blockCount = [aDecoder decodeInt32ForKey:@"blockCount"];
self.chunkCount = [aDecoder decodeInt32ForKey:@"chunkCount"];
}
return self;
}

@end
5 changes: 4 additions & 1 deletion QiniuSDK/QiniuResumableUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "QiniuResumableUploader.h"
#import "QiniuResumableClient.h"
#import "QiniuUtils.h"

@implementation QiniuResumableUploader

Expand Down Expand Up @@ -116,9 +117,10 @@ - (void) uploadFile:(NSString *)filePath
[self.delegate uploadProgressUpdated:filePath percent:percent];
}
}
complete:blockComplete];
complete:weakBlockComplete];
} else {
if (extra.notifyErr != nil) {
error = qiniuErrorWithOperation(operation, error);
extra.notifyErr(blockIndex, blockSize1, error);
}
}
Expand All @@ -145,6 +147,7 @@ - (void) uploadFile:(NSString *)filePath
progress:nil
complete:^(AFHTTPRequestOperation *operation, NSError *error) {
if (error) {
error = qiniuErrorWithOperation(operation, error);
[self.delegate uploadFailed:filePath error:error];
}else{
NSDictionary *resp = operation.responseObject;
Expand Down
1 change: 1 addition & 0 deletions QiniuSDK/QiniuSimpleUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (void) uploadFile:(NSString *)filePath
}
} complete:^(AFHTTPRequestOperation *operation, NSError *error) {
if (error) {
error = qiniuErrorWithOperation(operation, error);
[self.delegate uploadFailed:filePath error:error];
}else{
NSDictionary *resp = operation.responseObject;
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/QiniuUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

NSError *qiniuError(int errorCode, NSString *errorDescription);

NSError *qiniuErrorWithRequest(AFHTTPRequestOperation *request);
NSError *qiniuErrorWithOperation(AFHTTPRequestOperation *operation, NSError *error);
47 changes: 18 additions & 29 deletions QiniuSDK/QiniuUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,26 @@
return [NSError errorWithDomain:kQiniuErrorDomain code:errorCode userInfo:[NSDictionary dictionaryWithObject:errorDescription forKey:kQiniuErrorKey]];
}

NSError *qiniuErrorWithRequest(AFHTTPRequestOperation *request) {
NSDictionary *dic = nil;
NSError *httpError = nil;
long errorCode = 400;

if (request) {
NSDictionary *responseObj = request.responseObject;
if ([responseObj isKindOfClass:NSDictionary.class]) {
dic = responseObj;
}
httpError = [request error];
errorCode = [request response].statusCode;
NSError *qiniuErrorWithOperation(AFHTTPRequestOperation *operation, NSError *error) {

if (operation == nil || operation.responseObject == nil) {
return error;
}

NSString *errorDescription = nil;
if (dic) { // Check if there is response content.
NSObject *errorObj = [dic objectForKey:kQiniuErrorKey];
if (errorObj) {
errorDescription = (NSString *)errorObj;
}

NSMutableDictionary *userInfo = nil;
NSInteger errorCode = -1;

if ([operation.responseObject isKindOfClass:NSDictionary.class]) {
userInfo = [NSMutableDictionary dictionaryWithDictionary:operation.responseObject];
}
if (errorDescription == nil && httpError) { // No response, then try to retrieve the HTTP error info.
errorCode = [httpError code];
errorDescription = [httpError localizedDescription];
errorCode = [operation.response statusCode];

if (!userInfo) {
userInfo = [NSMutableDictionary init];
}

NSString *reqid = [[request.response allHeaderFields] objectForKey:@"X-Reqid"];
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:reqid forKey:@"reqid"];
if (errorDescription) {
[userInfo setObject:errorDescription forKey:kQiniuErrorKey];
}


NSString *reqid = [[operation.response allHeaderFields] objectForKey:@"X-Reqid"];
[userInfo setObject:reqid forKey:@"reqid"];

return [NSError errorWithDomain:kQiniuErrorDomain code:errorCode userInfo:userInfo];
}
56 changes: 55 additions & 1 deletion QiniuSDKTests/QiniuSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)setUp
// Prepare the uptoken
// token with a year, 14.2.23
_token = @"6UOyH0xzsnOF-uKmsHgpi7AhGWdfvI8glyYV3uPg:m-8jeXMWC-4kstLEHEMCfZAZnWc=:eyJkZWFkbGluZSI6MTQyNDY4ODYxOCwic2NvcGUiOiJ0ZXN0MzY5In0=";

_done = false;
_progressReceived = false;
}
Expand Down Expand Up @@ -79,6 +79,8 @@ - (void)uploadFailed:(NSString *)theFilePath error:(NSError *)error
_done = YES;
_error = error;
NSLog(@"Upload Failed: %@ - Reason: %@", theFilePath, error);
NSString *reqid = [error.userInfo valueForKey:@"reqid"];
XCTAssertFalse(reqid == nil, @"no reqid");
}

- (NSString *) timeString {
Expand Down Expand Up @@ -169,6 +171,17 @@ - (void)testResumableUploadSmall
XCTAssertEqual(_succeed, YES, "ResumableUpload failed, error: %@", _error);
}

- (void)testResumableUploadWithoutKey
{
QiniuResumableUploader *uploader = [[QiniuResumableUploader alloc] initWithToken:_token];
uploader.delegate = self;

NSLog(@"resumable upload");
[uploader uploadFile:_filePath key:nil extra:nil];
[self waitFinish];
XCTAssertEqual(_succeed, YES, "ResumableUpload failed, error: %@", _error);
}

// */

- (void)testResumableUploadWithParam
Expand Down Expand Up @@ -205,6 +218,47 @@ - (void)testResumableUploadMedium
XCTAssertEqual(_succeed, YES, "ResumableUpload failed, error: %@", _error);
}

- (void)testEncodeExtra
{
QiniuResumableUploader *uploader = [[QiniuResumableUploader alloc] initWithToken:_token];
uploader.delegate = self;
QiniuRioPutExtra *extra = [[QiniuRioPutExtra alloc] init];
extra.notify = ^(int blockIndex, int blockSize, QiniuBlkputRet* ret) {
NSLog(@"[testEncodeExtra]notify for data persistence, blockIndex:%d, blockSize:%d, offset:%d ctx:%@",
blockIndex, blockSize, (unsigned int)ret.offset, ret.ctx);
};

NSString *key = [NSString stringWithFormat:@"test-encode-extra-%@.mp4", [self timeString]];
[uploader uploadFile:_fileMedium key:key extra:extra];

NSData *serialized;
int loop = 40;
while (loop > 0) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
if (extra.uploadedBlockNumber > 0) {
[extra cancelTasks];
serialized = [NSKeyedArchiver archivedDataWithRootObject:extra];
NSLog(@"extra.uploadedBlockNumber: %d", (unsigned int)extra.uploadedBlockNumber);
break;
}
loop--;
}
if (loop == 0) {
XCTFail(@"upload block time out");
}

QiniuRioPutExtra *newExtra = [NSKeyedUnarchiver unarchiveObjectWithData:serialized];
newExtra.notify = ^(int blockIndex, int blockSize, QiniuBlkputRet* ret) {
NSLog(@"[testEncodeExtra,new]notify for data persistence, blockIndex:%d, blockSize:%d, offset:%d ctx:%@",
blockIndex, blockSize, (unsigned int)ret.offset, ret.ctx);
XCTAssertTrue([extra.progresses[blockIndex] isKindOfClass:[NSNull class]], @"index of progresses should be nil, index: %d", blockIndex);
};

[uploader uploadFile:_fileMedium key:key extra:newExtra];
[self waitFinish];
XCTAssertEqual(_succeed, YES, "ResumableUpload reuse extra failed, error: %@", _error);
}


//- (void)testResumableUploadLarge
//{
Expand Down