从我的IOS应用程序上载Dropbox上的多个图像

时间:2014-06-06 10:38:57

标签: ios iphone dropbox

我正在开发一个应用程序,我从我的iPhone上传Dropbox上的多个图像。 当我上传我的图像时,一次只上传5张图片,无论我选择5张或5张以上的图像。 以下是我在Dropbox ::

上传图片的代码
- (void)_startUpload:(UIImage *)image
{
    UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:bgTask];
        NSLog(@"%@",(NSString*)countere);
    }];
    // while(countere != 0){
    HUD=[[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:HUD];

    HUD.labelText=@"Please wait for Uploading";
    HUD.dimBackground=YES;
    [HUD show:YES];

    //NSString *fileString=@"/%@",albumNAME;
    //  NSData * JPEGData = UIImageJPEGRepresentation(image, 1.0);
    self.file = [NSString stringWithFormat:@"/%@",albumNAME];
    NSLog(@"File Name ---> %@",self.file);
    NSInteger randomNumber = arc4random() % 100;
    NSString *filename = [NSString stringWithFormat:@"PicBackMan-%ld.jpg",(long)randomNumber];
    NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                            NSUserDomainMask,
                                                            YES);
    countere--;
    NSString *localPath = [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"image.jpg"];;
    NSLog(@"local Path ----> %@",localPath);
    NSString *destDir = self.file;
    // [presenter presentHud:@"Uploading"];
    [[self restClient] uploadFile:filename toPath:destDir
                    withParentRev:nil fromPath:localPath];
    //[NSThread sleepForTimeInterval:0.5];
    [[UIApplication sharedApplication] endBackgroundTask:bgTask];
    //   }
    [self performSelectorOnMainThread:@selector(savingDone) withObject:nil waitUntilDone:YES];

}

在日志中我收到以下错误::

2014-06-06 15:51:55.977 PicBackMan_1 [3499:60b] [警告] DropboxSDK:向/1/files_put/dropbox/Like-2/PicBackMan-12.jpg发出错误请求 - (-1005)错误Domain = NSURLErrorDomain Code = -1005“操作无法完成。(NSURLErrorDomain错误-1005。)”UserInfo = 0xa5d4570 {destinationPath = / Like-2 / PicBackMan-12.jpg,sourcePath = / Users / bettermac9 / Library /应用程序支持/ iPhone模拟器/ 7.1 /应用程序/ F51F7F8F-91C5-4E67-90E6-4218941D3A67 / Documents / image.jpg}

2014-06-06 15:51:56.500 PicBackMan_1 [3499:60b] [警告] DropboxSDK:向/ 1 / metadata / dropbox / Photos发出错误请求 - (404)找不到路径'/ Photos'

2014-06-06 15:51:56.500 PicBackMan_1 [3499:60b] restClient:loadMetadataFailedWithError:无法完成操作。 (dropbox.com错误404。)

我不明白为什么有连接超时? 在Dropbox上传的照片,其中一些未正确存储且图像未查看错误。 请帮助我找到更好的解决方案。

感谢您宝贵的时间。

1 个答案:

答案 0 :(得分:0)

尝试序列化您的上传内容,而不是尝试一次性完成所有操作。对于某些操作(如上传文件),Dropbox必须序列化服务器上​​的写入,因此即使您一次启动五次上传,也只能实际处理一次。您尝试同时执行的上传次数越多,后续的内容越有可能在他们等待的时候超时。