Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Is there any way to know what file is being worked on when the progress block is called? See the working code below - I'd like to be able to put an update on the screen so that the user knows which file is being uploaded. I know that it could be uploading several files synchronously - so this is why I'd like to know which one it is referring to each time the progress block is called.
[[[dbClient.filesRoutes uploadUrl:remoteFile inputUrl:[NSURL fileURLWithPath:localFile]] setResponseBlock:^(DBFILESFileMetadata *metadata, DBFILESUploadError *uploadError, DBRequestError *error) { if (metadata) { NSLog(@"The upload completed successfully."); NSLog(@"File metadata:"); NSLog(@"%@", metadata); } else if (uploadError) { NSLog(@"Something went wrong with the upload:"); NSLog(@"%@", uploadError); } else if (error) { NSLog(@"Something went wrong with the API call:"); NSLog(@"%@", error); } ++self.filesUploaded; [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_FILE_UPLOADED object:self]; }] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { float percentDone = (float)totalBytesWritten/(float)totalBytesExpectedToWrite*(float)100; self.alert.message = $str(@"Uploading File %0.0f%%\n\n",percentDone); }];
Thank you,
Eric
Hi Eric, yes, you can disambiguate the different progress blocks by setting a variable inside each. You can then factor out the rest of the handling if you want. For example:
- (void)progressCallback:(NSString*)identifier bytesWritten:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite { NSLog(@"%@: bytesWritten: %lld, totalBytesWritten: %lld, totalBytesExpectedToWrite: %lld", identifier, bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); }
...
}] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { NSString *identifier = @"this is #1"; // or whatever you want [self progressCallback:identifier bytesWritten:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite]; }];
...
}] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { NSString *identifier = @"this is #2"; // or whatever you want [self progressCallback:identifier bytesWritten:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite]; }];
Hope this helps!
Thanks for the quick reply Greg. But I don't think that's what I'm looking for. Apologies for not being more clear. As you can see below, I'm calling uploadUrl in a loop - for each file that needs to be uploaded. Therefore the setProgressBlock is getting called for each of the files being uploaded synchronously. I'd like to know for which file the progress information is for. Any way to know this?
-(void) uploadLocalChanges { self.uploadLocalChangesCalled = YES; DBUserClient *dbClient = [DBClientsManager authorizedClient]; NSMutableSet* allLocalFiles = [NSMutableSet set]; [allLocalFiles addObjectsFromArray:self.localFiles.allKeys]; for (NSString* file in allLocalFiles) { NSDate* localDate = [self.localFiles objectForKey:file]; NSDate* remoteDate = [self.remoteFiles objectForKey:file]; NSDate* lastSyncLocalDate = [self.lastSyncLocalFiles objectForKey:file]; if (remoteDate == nil || (lastSyncLocalDate != nil && localDate > lastSyncLocalDate)) { ++self.filesToUpload; //NSLog(@"Uploading file %@",file); NSString* remoteFile = [@"/" stringByAppendingString:file]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* appPath = [[paths objectAtIndex:0] stringByAppendingString:@"/"]; NSString* localFile = [appPath stringByAppendingString:file]; [[[dbClient.filesRoutes uploadUrl:remoteFile inputUrl:[NSURL fileURLWithPath:localFile]] setResponseBlock:^(DBFILESFileMetadata *metadata, DBFILESUploadError *uploadError, DBRequestError *error) { if (metadata) { /* NSLog(@"The upload completed successfully."); NSLog(@"File metadata:"); NSLog(@"%@", metadata); */ } else if (uploadError) { NSLog(@"Something went wrong with the upload:"); NSLog(@"%@", uploadError); } else if (error) { NSLog(@"Something went wrong with the API call:"); NSLog(@"%@", error); } ++self.filesUploaded; [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_FILE_UPLOADED object:self]; }] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { [self updateFileStatusPercent:@"Uploading ..." totalBytesWriten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite]; // Here we can monitor the progress of the transfer: //NSLog(@"bytesWritten: %lld, totalBytesWritten: %lld, totalBytesExpectedToWrite: %lld", bytesWritten, totalBytesWritten, totalBytesExpectedToWrite); }]; } } if (self.filesToUpload == 0) [[NSNotificationCenter defaultCenter] postNotificationName:NOTIF_FILE_UPLOADED object:self]; }
Thank you,
Eric
Apologies - I was being dense. I forgot that I had access to the file variable in the setProgress block. I'm good now.
Many thanks!
Eric
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!