最近用Qiniu iOS-SDK 里面的Demo尝试上传视频。 上传一半左右时出错。
出错信息:
2013-11-02 23:06:19.968 QiniuDemo[265:60b] Failed uploading /private/var/mobile/Applications/XXXXXXXX-140A-487D-A77E-XXXXXXXX/tmp/2013-11-03-03-05-52mov with error: Error Domain=QiniuErrorDomain Code=2 "The operation couldn’t be completed. (QiniuErrorDomain error 2.)" UserInfo=0x155b8c30 {error=The request timed out}
少做修改的上传代码:
QiniuDemo/QiniuViewController.m
- (void)uploadContent:(NSDictionary *)theInfo {
//obtaining saving path
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat: @"yyyy-MM-dd-HH-mm-ss"];
//Optionally for time zone conversions
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSString *timeDesc = [formatter stringFromDate:[NSDate date]];
[formatter release];
//extracting image from the picker and saving it
NSString *mediaType = [theInfo objectForKey:UIImagePickerControllerMediaType];
NSString *key = [NSString stringWithFormat:@"%@%@", timeDesc, @".mov"];
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:key];
NSLog(@"Upload Path: %@", filePath);
NSData *webData = [NSData dataWithContentsOfFile:[[theInfo objectForKey:UIImagePickerControllerMediaURL] path]];
[webData writeToFile:filePath atomically:YES];
[self uploadFile:filePath bucket:QiniuBucketName key:key];
}
这是上传客户端判断超时,七牛 iOS-SDK 用了 ASIHTTPRequest 库,其有默认超时时间,你可以将其调大,可参考这个。
如果上传的资源比较大,推荐使用断点续上传,看这里 。
同时请检查上传链路是不是有问题。