Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Marco N.2
10 years agoNew member | Level 1
chunked uploading iOS
Uploading large files is causing the -1101 error in my app frequently from my customers and also when I test. I am using a 50 Mbps internet connection on a 170 MB file size upload.
Any ideas or wor...
Greg-DB
Dropbox Community Moderator
10 years agoBy the way, here's a quick sample I put together. I haven't tested this fully, so don't just ship this, but I believe the basics are right:
- (void) doTest {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"Running test...");
// Write a file to the local documents directory
NSString *text = @"Hello world. Usually something much longer here.";
NSString *filename = @"working-draft.txt";
NSString *localDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
self.localPath = [localDir stringByAppendingPathComponent:filename];
[text writeToFile:self.localPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
self.dbClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.dbClient.delegate = self;
// Start the upload. No upload ID known yet
[self.dbClient uploadFileChunk:nil offset:0 fromPath:self.localPath];
}
}
- (void)restClient:(DBRestClient *)client uploadedFileChunk:(NSString *)uploadId newOffset:(unsigned long long)offset
fromFile:(NSString *)localPath expires:(NSDate *)expiresDate {
NSLog(@"uploadedFileChunk: %@, newOffset: %llu, fromFile: %@, expires: %@", uploadId, offset, localPath, expiresDate);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attrs = [fileManager attributesOfItemAtPath:self.localPath error: NULL];
// in real use, there's probably a dangerous race condition here in checking the size each time, but this is just for demonstration purposes
if (offset >= [attrs fileSize]) {
// all data has been uploaded
NSLog(@"Finishing upload...");
[self.dbClient uploadFile:@"chunked_uploaded_file.txt" toPath:@"/" withParentRev:nil fromUploadId:uploadId];
} else {
// more data to upload
NSLog(@"Continuing upload...");
[self.dbClient uploadFileChunk:uploadId offset:offset fromPath:localPath];
}
}
- (void)restClient:(DBRestClient *)client uploadFileChunkFailedWithError:(NSError *)error {
NSLog(@"uploadFileChunkFailedWithError: %@", error);
// TODO: retry
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!