I have an iOS app that uses Core Data for persistent data storage. I integrated Dropbox as a way for users to perform a a backup of the persistent store file (appname.sqlite).
A UIButton calls a method to see if a file already exists on 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];
}
The loadedMetadata delegate method initiates the upload with the rev number of the existing file (if one exists).
-(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];
}
This works well for reasonably small files or large files over a perfect network connection but any small error during the upload cancels the whole process. I would like to switch to using the chunked upload methods but I'm at a loss as to how to actually do the 'chunking' of the .sqlite file.
I can't seem to find any sample apps that are using the chunked upload that I can learn from and the documentation simply says to provide the file in chunks.
So, my questions are:
Is the chunked upload the right approach to addressing the user issues with uploading large files over a possibly spotty network connection?
Can you point me to sample code / app / documentation for 'chunking' a file? I'm pretty comfortable with the Dropbox SDK.
Thanks!
I'm going to answer this myself just in case anyone else has the same issue.
It turns out that I was making this way more difficult than it needed to be. The Dropbox SDK handles chunking the files so I just needed to initate the transfer and react to the delegate calls. The methods used are:
To send a file chunk - for the first chunk, use nil for the uploadId and 0 for the offset:
After sending the last chunk, use this method to commit the upload:
I handled the delegate method as follows:
Since the main problem that I was trying to address was handling poor connections I implemented delegate method for failed chunk uploads: