I am going to answer it myself just in case anyone has a different problem.
Turns out I did it a lot harder than I needed. The Dropbox SDK handles file fragmentation, so I just need to initiate the transfer and respond to delegate calls. Methods used:
To send a fragment of a file - for the first fragment use nil for uploadId and 0 for offset:
- (void)uploadFileChunk:(NSString *)uploadId offset:(unsigned long long)offset fromPath:(NSString *)localPath;
After sending the last fragment, use this method to commit the download:
- (void)uploadFile:(NSString *)filename toPath:(NSString *)parentFolder withParentRev:(NSString *)parentRev fromUploadId:(NSString *)uploadId;
I processed the delegate method as follows:
- (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) {
Since the main problem I was trying to deal with was handling weak connections, I applied the delegation method to unsuccessful package downloads:
- (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 {
Eric
source share