user3932017
user3932017

Reputation: 45

Checking for Parallel Download in Amazon S3 for iOS

Good day. I would like to know if there is a way using standard iOS SDK for Amazon to downloads multiple images in parallel.

It seems like it is downloading in sequence, than parallel.

I use this delegate to count the number of images downloaded, against the total requested.

-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response

When I check timestamps when each download finishes, the duration for each image is about 3-4secs each:

The images have almost the same file size (500KB), so I am under the impression that the images are downloaded in sequence, rather than parallel.

The asynchronous download requests are called in a separate thread with different transfer manager instances:

[self.transferManager downloadFile:targetFile bucket:S3_BUCKET key:s3Key]

Is there a way to add something in the code to download images in parallel? Also, is there a procedure to know/monitor if all download requests are moving in parallel?

Upvotes: 0

Views: 426

Answers (1)

Trond Kristiansen
Trond Kristiansen

Reputation: 2446

I am not sure which version of AWS SDK iOS you are using, but for version 2 you can control whether the asynchronous uploads/downloads should be in sequence or parallel. There is a lot of very useful information for more details on these topics here.

I attach an example of how to upload files in parallel below. Download would be the same. Hope this helps. T.

-(void) uploadAllFileRequests
{
    AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
    NSMutableArray *tasks = [NSMutableArray new];

    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");
                }
            } else {

                NSLog(@"SUCCESS");
            }
            return nil;     
        }]];
    }
    [[BFTask taskForCompletionOfAllTasks:tasks] continueWithSuccessBlock:^id(BFTask *task)
     {
         NSLog(@"Finished all");
         return nil;
     }];
}

Here, self.arrayOfUploadRequests is an array of AWSS3TransferManagerUploadRequest.

Upvotes: 1

Related Questions