lundi 13 juin 2016

S3 TransferUtility silently failing upon download (android aws sdk)

I followed the documentation on http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/s3transferutility.html

I first initialized cognito, then S3, then transfer utility, then I download and set a listener. Unfortunately the listener never fires any events so I never get any notifications. Please check the code below. I've attempted to look at a few SO posts and some github comments on it but still struggle. Some of the advice called for setting the listener to a class variable so that way I could establish a reference to it. All in all, the transfer listener I've created does not fire any events. Nor do I get any indication of anything happening once I invoke the download.

CODE:

TransferUtility transferUtility;
TransferListener listener;
method1(options){
    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
            getApplicationContext(),
            "Somepoolid", // Identity Pool ID
            Regions.fromName("someregion") // Region
    );
    AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
    s3.setRegion(Region.getRegion(Regions.fromName(options.getString("region"))));
    transferUtility = new TransferUtility(s3, getApplicationContext());

    listener = new TransferListener() {

        @Override
        public void onStateChanged(int id, TransferState state) {
            System.out.println("state changed");
        }
        @Override
        public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
            System.out.println("progress changed");
        }
        @Override
        public void onError(int id, Exception ex) {
            System.out.println("error changed");

        }
    };
}
method2(observer){
    TransferObserver observer = transferUtility.download(
                    (String)map.get("bucket"),
                    (String)map.get("key"),
                    new File((String)map.get("path"))
            );
            observer.setTransferListener(listener);
}

Aucun commentaire:

Enregistrer un commentaire