3

I've read as much as I can here on this topic and I've crawled through the documentation (AWS 2.2.9) and am using their example code as closely as I can and I'm stuck. Here's what I've done for setup:

Manifest -

relevant permissions - "android.permission.INTERNET" and "android.permission.ACCESS_NETWORK_STATE"

service -

android:name= "com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true"

I have my bucket set up and also credentials for Cognito. Here is the code I've added for doing the upload:

File f = getVideoFile(activity);

...

TransferObserver observer = sTransferUtility.upload(Constants.BUCKET_NAME, f.getName(), f);

    observer.setTransferListener(new TransferListener() {
        @Override
        public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
            Log.e("Transfer", "Percent Complete = " + bytesCurrent / bytesTotal * 100);
        }

        @Override
        public void onStateChanged(int id, TransferState state) {
            Log.e("Transfer", "onStateChanged");
            Log.e("Transfer", "state = " + state);
        }

        @Override
        public void onError(int id, Exception ex) {
            Log.e("Transfer", "Error = " + ex.getMessage());
        }
    });

I've also temporarily added a wait loop after to see if I'm just being impatient but it just shows state = WAITING until I kill the app:

    TransferState state = observer.getState();
    while (state != TransferState.COMPLETED) {
        Log.e("Transfer", "state = "  + state);
        try {
            Thread.sleep(10000);
            state = observer.getState();
        } catch (Exception e) {
            Log.e("Transfer", "exception " + e.getMessage());
        }
    }

All of this is happening inside a fragment. I see no errors being reported (I understand that others have observed that missing configuration can result in this behavior but I think I've done everything I am supposed to do, here).

I would be grateful to hear of anything I've overlooked or need to try to get further information.

Edit:

I am not suspicious that the whole problem is not with the code but rather with the configuration that I've got.

My Cognito and bucket Id look like the following (but aren't exactly these):

COGNITO_POOL_ID: "us-east-1:abcdefgh-abcd-efgh-ijkl-mnopqrstuvwxy" BUCKET_NAME: "MyBucket"

I am also curious as to whether the key should be the file name in my .upload() should include the path or just the filename. I've tried both but which of these would be correct:

/storage/emulated/0/Android/data/com.blah.blah/files/video.mp4

or

video.mp4

Good so far?

Thanks.

-VAR

VAR
  • 31
  • 4
  • Are you calling refresh on the TransferObserver? What state is it reporting stuck in? – WestonE Dec 05 '15 at 01:42
  • WestonE, I've added the refresh. The reporting state is stuck on "WAITING". – VAR Dec 07 '15 at 15:33
  • Is this still an issue? Are you calling this in a background thread? What if you make the call outside of a fragment? Are you sure the file exists? Can you download a file? Also video.mp4 should be fine. – WestonE Dec 14 '15 at 19:19
  • Yes, still an issue. Yes, in a background thread. Haven't tried it outside a fragment (I suppose that may be the next trial). The file exists, and I am able to see the total size in bytes using TransferObserver::getBytesTotal(); – VAR Dec 14 '15 at 21:15
  • I haven't needed to download from this app but I'll give it a try. – VAR Dec 14 '15 at 21:16
  • I suppose you have also checked for error messages from log cat? Is this happening on a stable wifi connection or something flaky like 3g? What is the size of the video? Is this happening on all versions of Android or just a simple one? – WestonE Dec 19 '15 at 00:38
  • Over the course of looking at my work and trying your suggestions I found problems with how I had the service configured. Things are finally working and thank you for all your input, WestonE – VAR Jan 12 '16 at 18:36
  • @VAR, can you answer the question explaining the solution? I have the same problem, and probably others will have too. – brnfd Feb 13 '16 at 16:46

3 Answers3

2

I had the same issue and the following thread gave me the solution.

Uploading files doesn't work with TransferUtility Amazon S3 in Android

In the manifest I had to put the transfer utility service inside the application tag.

Community
  • 1
  • 1
2

Put this inside the application tag in AndroidManifest.xml

<service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" 
android:enabled="true" />
Ken Ratanachai S.
  • 3,307
  • 34
  • 43
0

I was doing the upload inside a AsyncTask class and the state never changed, keep WATING. After switch the code to inside de Activity works properly. So, try call TransferObserver observer = transferUtility.upload() in your activity.

Aduílio Silva
  • 116
  • 1
  • 3