Jerin Wan
Jerin Wan

Reputation: 51

What does AWSS3TransferManagerErrorCancelled mean and how to get rid of it?

I recently try to learn how to use Amazon AWS iOS SDK since I would like to put some files on server allowed to be downloaded by app users.

I have download the samples provided by Amazon and studied them: https://github.com/awslabs/aws-sdk-ios-samples/tree/master/S3TransferManager-Sample/Objective-C

Thing went pretty well with uploading files to my S3 bucket until I tried to download the images from the bucket.

I traced the codes and found where the problem happened.

[[transferManager download:self.downloadRequest1] continueWithExecutor:[BFExecutor mainThreadExecutor] withBlock:^id(BFTask *task) {
    if (task.error != nil){
        if(task.error.code != AWSS3TransferManagerErrorCancelled && task.error.code != AWSS3TransferManagerErrorPaused){
            NSLog(@"%s Error: [%@]",__PRETTY_FUNCTION__, task.error);
            self.downloadStatusLabel.text = StatusLabelFailed;
        }
    } else {
        self.downloadRequest1 = nil;
        downloadCount++;
        if(3 == downloadCount){
            self.downloadStatusLabel.text = StatusLabelCompleted;
        }
    }
    return nil;
}];

I printed the value of task.error.code and found it is 1 (AWSS3TransferManagerErrorCancelled). Since there is no exception handling of AWSS3TransferManagerErrorCancelled, the program does not show error message and failed to download files.

I tried to find what AWSS3TransferManagerErrorCancelled means but no luck.

Does anyone know why the error code = 1 (AWSS3TransferManagerErrorCancelled) and how to solve it? I believe I must miss something very simple considering this is an tutorial provided by Amazon.

Upvotes: 1

Views: 138

Answers (1)

Jerin Wan
Jerin Wan

Reputation: 51

After some studies, finally I figured out it is Permissions issue.

So when I was creating a Identity Pool, the system asked you if you want to enable access to Unauthenticated Identities. And if you enable this option, AWS would give you a default unauthenticated Identities postfixed by Unauth_DefaultRole. The thing is AWS does not automatically give the permission of "Get" to this identity. You still need to add this Action into the policy of xxxUnauth_DefaultRole.

So, here is my modified policy to allow to unauthenticated users to download files from my bucket.

{
"Version": "2012-10-17",
"Statement": [{
    "Action": [
        "mobileanalytics:PutEvents",
        "cognito-sync:*",
        "s3:ListBucket",
        "s3:Get*"
    ],
    "Effect": "Allow",
    "Resource": [
        "*"
    ]
}]
}

Hope this can help someone who is also new for AWS.

Upvotes: 1

Related Questions