Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWSS3TransferUtility continuously drops upload, progress goes back to zero #444

Closed
msencenb opened this issue Aug 11, 2016 · 9 comments
Closed

Comments

@msencenb
Copy link

msencenb commented Aug 11, 2016

Using Xcode 7.3.1, iPhone 9.3 simulator, and AWSS3 2.4.6, to create an upload task. I'm using the image picker to grab one of the stock photos off of the simulator, and then trying to upload it's raw binary data to S3 using AWSS3TransferUtility like so (some variables changed like bucket name):

    NSData *dataToUpload = UIImagePNGRepresentation(image);

    AWSS3TransferUtilityUploadExpression *expression = [AWSS3TransferUtilityUploadExpression new];
    expression.progressBlock = ^(AWSS3TransferUtilityTask *task, NSProgress *progress) {
        dispatch_async(dispatch_get_main_queue(), ^{
            // Do something e.g. Update a progress bar.
            NSLog(@"fraction completed: %f", progress.fractionCompleted);
        });
    };

    AWSS3TransferUtilityUploadCompletionHandlerBlock completionHandler = ^(AWSS3TransferUtilityUploadTask *task, NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^{
            // Do something e.g. Alert a user for transfer completion.
            // On failed uploads, `error` contains the error object.
            if (error) {
                NSLog(@"upload failed error");
            } else {
                NSLog(@"successfully uploaded");
            }
        });
    };

    AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
    [[transferUtility uploadData:dataToUpload
                          bucket:@"mybucket"
                             key:fileKey
                     contentType:@"png"
                      expression:expression
                completionHander:completionHandler] continueWithBlock:^id(AWSTask *task) {
        if (task.error) {
            NSLog(@"Error: %@", task.error);
        }
        if (task.exception) {
            NSLog(@"Exception: %@", task.exception);
        }
        if (task.result) {
            NSLog(@"beginning upload");
        }

        return nil;
    }];

Unfortunately, the image gets to a certain percentage, and then simply drops back down to zero like this log:

fraction completed: 0.938850
fraction completed: 0.003058
fraction completed: 0.006116

The error or completion handler is never called, and I've tried on several wifi networks, even leaving my computer open for as many as ten minutes. It simply drops to zero repeatedly after restarting itself. Any tips to make this actually work? I could save the data to a file, but the binary upload option seems much easier at face value.

@msencenb
Copy link
Author

This was an error on my part with granting the cognito role access to my S3 bucket. The link that provided me the most clear instructions is here, under the 'grant access to your s3 resources' section

@pratibha-bhandari
Copy link

In my case, when network goes down the progress gets stop and when network comes back then the upload progress gets to zero. It is simply getting restart with network reachability. Did you face this issue in your case?

@msencenb
Copy link
Author

msencenb commented Oct 8, 2016

No, I did have problems with network reachability, but I also haven't tested that extensively in my app.

@jatindaveifuturz
Copy link

i am facing same issue , is there any solution?

@msencenb
Copy link
Author

@jatindaveifuturz if you are facing the same problem as the original issue, see me comment above about cognito role access.

@CSabari
Copy link

CSabari commented Aug 14, 2018

@msencenb : Try like this let percentageUploaded:Float = Float(progress.fractionCompleted) * 100

@tmaly1980
Copy link

@msencenb The link you provided is expired, I'm curious though what the access is having to do with the issue, and how to fix it? Why does the progress show anything at all? Seems almost like it's never able to actually complete and tries from scratch again.

For me, I see it sit at 0% for a while, then suddenly go to 100% pretty quickly, without actually calling the completion handler, then restarts to no progress and retrying again. I'm using a cell hotspot, but the file is only 23 MB.

@msencenb
Copy link
Author

@tmaly1980 I'm not sure why the progress was updated at all, just that changing my access level fixed it.

I can't quite remember what I did, but I believe it was modifying my anonymous cognito pool in IAM to have permissions on the s3 bucket it needed.

@atierian
Copy link
Member

@tmaly1980 which version of AWS SDK for iOS are you using?
In 2.31.1 we released a fix that likely addresses what you're seeing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants