Aws-sdk-android: Android 7.0 TransferState always WAITING

Created on 22 Sep 2016  Â·  18Comments  Â·  Source: aws-amplify/aws-sdk-android

Hi.

I'm submitting two pictures one by one. First one always goes through, but the second one always get stuck (after some retries, it gets through somehow!?).

First image is thumb and is being sent like this:

        File thumbFile = new File(thumbImagePath);
        TransferObserver obsThumb = transferUtility.upload(
                s3BucketNameForPhotos,
                "T" + imageId + ".jpg",
                thumbFile, new ObjectMetadata());
        obsThumb.setTransferListener(new UploadListener());
        i += simulateWaitForCompletion(obsThumb);

Second image is original picture and is being sent like this:

        TransferUtility newtransferUtility = getTransferUtility(context);
        TransferObserver obsOriginalPicture = newtransferUtility.upload(
                s3BucketNameForPhotos,
                imageId + ".jpg",
                file, new ObjectMetadata());
        obsOriginalPicture.setTransferListener(new UploadListenerForBigPicture()); 
        i += simulateWaitForCompletion(obsOriginalPicture);

Implementation of simulateWaitForCompletion method is (as suggested in this issue -> https://github.com/aws/aws-sdk-android/issues/91):

private int simulateWaitForCompletion(TransferObserver observer) {
        while (true) {
            if (TransferState.COMPLETED.equals(observer.getState())
                    || TransferState.FAILED.equals(observer.getState())) {
                if (TransferState.COMPLETED.equals(observer.getState())) {
                    return 0;
                } else {
                    return 1;
                }
            }
        }
    }

For the first picture, TransferState changes to COMPLETED state when upload completed. But for the second picture, it is always in WAITING state.

Known bug or? @fosterzhang anything?

Thanks.

Most helpful comment

@minbi onStateChanged callback never gets called in this scenario.

All 18 comments

Have you tried to listen for the change using:
public void onStateChanged(int id, TransferState state);

When you set the TransferListener, the above method should be part of its interface.
obsOriginalPicture.setTransferListener(new UploadListenerForBigPicture());

@minbi onStateChanged callback never gets called in this scenario.

If you do not wait for completion does it work?
What version of the SDK are you using (it may be worth upgrading to latest version if you are using an older version)?
Have you verified that the file is not null or empty?
Have you changed anything from the default config of the TransferUtility?

@wdane It will work, but I will have no information if the upload finished successfully. So I'm waiting for completion.

SDK version is updated to the latest. Not helping.

If the file is null or empty, I wouldn't even get to the code for uploading.

getTransferUtility method implementation is:

private TransferUtility getTransferUtility(Context context) {
        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                context,    // get the context for the application
                cognitoIdentityPoolId,    // Identity Pool ID
                region           // Region for your identity pool
        );

        ClientConfiguration cc = new ClientConfiguration();
        cc.setSocketTimeout(120000);

        AmazonS3 s3 = new AmazonS3Client(credentialsProvider, cc);
        return new TransferUtility(s3, context);
    }
}

But that's suggested in https://github.com/aws/aws-sdk-android/issues/119 so I guess it's ok.

@fosterzhang where are you? :)

I have solved this issue by refreshing TransferObserver object.

while(true) {
        transferObserver.refresh();  // Refresh TransferObserver object
       // YOUR CODE
} 

Above, code is tested in Nexus 6P with Android Nougat installed.

We'll take this feedback to work on our Transfer Utility docs, thanks!

@wdane so transferObserver.refresh(); is now a workaround?

@karthiksaligrama Are there any updates about this issue?

Hi @TOMKHAN, Can you upgrade to 2.6.18 (latest) and do the following?
We fixed bugs in the TransferListener.onStateChanged()in the latest release.

The following example demonstrates a way of waiting until both the uploads are complete. using CountDownLatch. Let us know if this works for you.

CountDownLatch latch = new CountDownLatch(2);

obsThumb.setTransferListener(new TransferListener() {
   @Override
   public void onStateChanged(int id, TransferState state) {
       if (state == TransferState.COMPLETED || state == TransferState.FAILED) {
         latch.countDown();
       }
   }
});

obsOriginalPicture.setTransferListener(new TransferListener() {
  @Override
   public void onStateChanged(int id, TransferState state) {
       if (state == TransferState.COMPLETED || state == TransferState.FAILED) {
         latch.countDown();
       }
   }
});

try {
    latch.await();
} catch (final InterruptedException exception) {

}

@kvasukib the Changelog for 2.6.18 doesn't indicate any changes for TransferListener - https://github.com/aws/aws-sdk-android/blob/master/CHANGELOG.md#release-2618

@snkashis We fixed a lot of bugs and improved the stability of TransferUtility since 2.6.16. The Changelog is not detailed enough to cover every fix. Sorry about that. Can you upgrade to the latest and give us any feedback you have?

I'm using 2.6.27 and still facing same issue.

I'm have this issue when start uploading in airplane mode. Nothing isn't happening when the connect is appear.

I have this issue with S3.How to solve??

@AlexeyKorshun and @sunithapremjee Can you open new issues with your specific details and individual reproduction steps? Especially on old issues like this one, we find that issues that look the same on the surface in fact have different root causes. Plus, separating the issues out makes it less likely to confuse different conversations in a long thread.

Uploadingfrom_AndroidApp_to_S3

I am trying to upload to S3bucket a photo from my android app.Please let me know what am I missing.I am new to this.I couldn't find anything in my S3 bucket and TransferState.COMPLETED == state is never called so save() function to update DynamoDb string data is also not getting called.@palpatim,Thanks for your reply.

@sunithapremjee Sorry for the inconvenience caused. Can you open a new issue with all the required details for us to investigate because we do not want to discuss this on the closed issue.

Also, when you open the new issue, can you try adding a log statement in onStateChanged() callback to see if you are getting the different state updates and post the logs in the new issue?

Ok...I'll open a new Isuue.

On Thu, Apr 25, 2019 at 3:47 PM Karthikeyan notifications@github.com
wrote:

@sunithapremjee https://github.com/sunithapremjee Sorry for the
inconvenience caused. Can you open a new issue with all the required
details for us to investigate because we do not want to discuss this on the
closed issue.

Also, when you open the new issue, can you try adding a log statement in
onStateChanged() callback to see if you are getting the different state
updates and post the logs in the new issue?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aws-amplify/aws-sdk-android/issues/199#issuecomment-486812976,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACLJQ2I6VVYGL56EUP63U2LPSIDDNANCNFSM4CQPGIWQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slomin picture slomin  Â·  4Comments

mockturtl picture mockturtl  Â·  4Comments

shabana0508 picture shabana0508  Â·  3Comments

yairkukielka picture yairkukielka  Â·  3Comments

cmbaykal picture cmbaykal  Â·  4Comments