Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm going to answer this myself just in case anyone else has the same issue. </p> <p>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:</p> <p>To send a file chunk - for the first chunk, use nil for the uploadId and 0 for the offset:</p> <pre><code>- (void)uploadFileChunk:(NSString *)uploadId offset:(unsigned long long)offset fromPath:(NSString *)localPath; </code></pre> <p>After sending the last chunk, use this method to commit the upload:</p> <pre><code>- (void)uploadFile:(NSString *)filename toPath:(NSString *)parentFolder withParentRev:(NSString *)parentRev fromUploadId:(NSString *)uploadId; </code></pre> <p>I handled the delegate method as follows:</p> <pre><code> - (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 &gt;= 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]]; } } </code></pre> <p>Since the main problem that I was trying to address was handling poor connections I implemented delegate method for failed chunk uploads:</p> <pre><code>- (void)restClient:(DBRestClient *)client uploadFileChunkFailedWithError:(NSError *)error { if (error != nil &amp;&amp; (self.uploadErrorCount &lt; 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 } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload