UIbutton调用一个方法来查看DropBox上是否已存在文件:
if([[DBSession sharedSession]islinked]) { Nsstring *foldername = [[self.dateFormatter stringFromDate:[NSDate date]] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]; Nsstring *destinationPath = [Nsstring stringWithFormat:@"/GradeBook Pro/Backup/%@/",foldername]; self.MetadataIndex = MetaDATA_REQUEST_BACKUP; [self.restClIEnt loadMetadata:destinationPath]; }
loadedMetadata委托方法使用现有文件的rev号(如果存在)启动上载.
-(voID) restClIEnt:(DBRestClIEnt *)clIEnt loadedMetadata:(DBMetadata *)Metadata{ SAVE_CORE_DATA; Nsstring *foldername = [[self.dateFormatter stringFromDate:[NSDate date]] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]; Nsstring *documentsDirectory = documentS_DIRECTORY; Nsstring *sourcePath = [Nsstring stringWithFormat:@"%@/GradeBookPro.sqlite",documentsDirectory]; Nsstring *destinationPath = [Nsstring stringWithFormat:@"/GradeBook Pro/Backup/%@/",foldername]; [self.restClIEnt uploadfile:@"GradeBookPro.sqlite" topath:destinationPath withParentRev:[[Metadata.contents lastObject]rev] fromPath:sourcePath]; }
这适用于完美网络连接上相当小的文件或大文件,但上传过程中的任何小错误都会取消整个过程.我想切换到使用分块上传方法,但我不知道如何实际执行.sqlite文件的’分块’.
我似乎无法找到任何使用我可以从中学习的分块上传的示例应用程序,文档只是说以块的形式提供文件.
所以,我的问题是:
>通过可能不稳定的网络连接上传大文件,分块上传是否正确解决用户问题?
>你能指点我为’chunking’文件的示例代码/ app /文档吗?我对DropBox SDK非常满意.
谢谢!
解决方法 我将自己回答这个问题,以防万一其他人有同样的问题.事实证明,我这样做比实际需要更困难. DropBox SDK处理文件分块,所以我只需要启动传输并对委托调用做出反应.使用的方法是:
要发送文件块 – 对于第一个块,使用nil作为uploadID,使用0作为offset:
- (voID)uploadfileChunk:(Nsstring *)uploadID offset:(unsigned long long)offset fromPath:(Nsstring *)localPath;
发送最后一个块后,使用此方法提交上传:
- (voID)uploadfile:(Nsstring *)filename topath:(Nsstring *)parentFolder withParentRev:(Nsstring *)parentRev fromUploadID:(Nsstring *)uploadID;
我按如下方式处理了委托方法:
- (voID)restClIEnt:(DBRestClIEnt *)clIEnt uploadedfileChunk:(Nsstring *)uploadID newOffset:(unsigned long long)offset fromfile:(Nsstring *)localPath expires:(NSDate *)expiresDate { unsigned long long fileSize = [[[NSfileManager defaultManager]attributesOfItemAtPath:[fileHelper localDatabasefilePath] error:nil]fileSize]; if (offset >= fileSize) { //Upload complete,commit the file. [self.restClIEnt uploadfile:DATABASE_filename topath:[fileHelper remoteDatabaseDirectory] withParentRev:self.databaseRemoteRevision fromUploadID:uploadID]; } else { //Send the next chunk and update the progress HUD. self.progressHUD.progress = (float)((float)offset / (float)fileSize); [self.restClIEnt uploadfileChunk:uploadID offset:offset fromPath:[fileHelper localDatabasefilePath]]; } }
由于我试图解决的主要问题是处理不良连接,我实现了失败的块上传的委托方法:
- (voID)restClIEnt:(DBRestClIEnt *)clIEnt uploadfileChunkFailedWithError:(NSError *)error{ if (error != nil && (self.uploadErrorCount < DROPBox_MAX_UPLOAD_FAILURES)) { self.uploadErrorCount++; Nsstring* uploadID = [error.userInfo objectForKey:@"upload_ID"]; unsigned long long offset = [[error.userInfo objectForKey:@"offset"]unsignedLongLongValue]; [self.restClIEnt uploadfileChunk:uploadID offset:offset fromPath:[fileHelper localDatabasefilePath]]; } else { //show an error message and cancel the process }}总结
以上是内存溢出为你收集整理的objective-c – 使用iOS Dropbox SDK进行核心数据的分块上传全部内容,希望文章能够帮你解决objective-c – 使用iOS Dropbox SDK进行核心数据的分块上传所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)