I am using BFTask together with AWS SDK v2 for iOS to upload and download files to AWS S3 storage. The following code works very well but I am wondering if anyone know how I can gain more control over the maximum number of uploads to allow and also better approach to receiving feedback for upload progress. I have read the documentation for both AWS SDK v2, the source code, and the BFTask readme but I am still uncertain how I gain control. For example, how would I edit the following code to limit the number of BFTasks to be run simultaneously to 3 and also receive number of bytes currently uploaded out of total number of bytes?
-(void) uploadAllFileRequests
{
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
__block int uploadCount = 0;
__block int uploadSuccess= 0;
__block int uploadFailure= 0;
NSMutableArray *tasks = [NSMutableArray new];
unsigned long totalnumberoffiles=self.arrayOfUploadRequests.count;
for (__block AWSS3TransferManagerUploadRequest *uploadRequestLocal in self.arrayOfUploadRequests)
{
[tasks addObject:[[transferManager upload:uploadRequestLocal] continueWithBlock:^id(BFTask *task) {
if (task.error != nil) {
if( task.error.code != AWSS3TransferManagerErrorCancelled
&&
task.error.code != AWSS3TransferManagerErrorPaused
)
{
NSLog(@"ERROR: %@",StatusLabelFailed);
uploadFailure ++;
}
} else {
uploadCount ++;
uploadSuccess ++;
NSLog(@"ETag: %@ %@ : %3.2f",[task.result valueForKey:@"ETag"], StatusLabelUploading, (uploadCount*1.0/totalnumberoffiles)*100.);
}
return nil;
}]];
}
[[BFTask taskForCompletionOfAllTasks:tasks] continueWithSuccessBlock:^id(BFTask *task)
{
NSLog(@"Finished: Success: %i - Failed: %i -",uploadSuccess,uploadFailure);
return nil;
}];
}
Here self.arrayOfUploadRequests
is an array containing AWSS3TransferManagerUploadRequest
. Suggestions are greatly appreciated. Thanks!