Reid
Reid

Reputation: 4524

Android App S3 upload not working. No error

I am working on building an android app that takes a picture and uploads that to Amazon S3. My code seems to be running fine, in that it is actually running (confirmed via debug breakpoints), however it is not uploading. I get no error messages, and log.d messages that I put into the app do not appear in the logcat.

I am using this amazon tutorial: http://docs.aws.amazon.com/mobile-hub/latest/developerguide/add-aws-mobile-user-data-storage.html#add-aws-mobile-user-data-storage-app

The first time I ran the code, I got an error complaining that TransferUtility.builder() didnt have .s3Client So I put that in.

Offending code:

private void uploadImage(){
        AWSConfiguration awsConfig =
                new AWSConfiguration(getActivity().getApplicationContext());
        AmazonS3Client s3Client = new AmazonS3Client(IdentityManager.getDefaultIdentityManager()
                .getCredentialsProvider().getCredentials());

        TransferUtility transferUtility =
                TransferUtility.builder()
                        .context(getActivity().getApplicationContext())
                        .awsConfiguration(awsConfig)
                        .s3Client(s3Client)
                        .build();

        TransferObserver uploadObserver =
                transferUtility.upload(
                        "sniffer-gps-app/UserDogPhotos/"+userId+photoFile.getName(),
                        photoFile);

        uploadObserver.setTransferListener(new TransferListener() {

            @Override
            public void onStateChanged(int id, TransferState state) {
                if (TransferState.COMPLETED == state) {
                    //todo something here
                    Log.d("S3", "done");
                    nextFragment();
                }

            }

            @Override
            public void onProgressChanged(
                    int id, long bytesCurrent, long bytesTotal) {
                Log.d("S3", "ID: "+id+"\r\nBytesCurrent: "+bytesCurrent+"\r\nBytesTotal: "+bytesTotal);
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(int id, Exception ex) {
                Log.d("S3", ex.toString());
                Integer ID = id;
                Log.d("S3", ID.toString());
            }

        });
    }

photoFile is a File object.

sniffer-gps-app is the bucket name

UserDogPhotos is a folder in the bucket

Upvotes: 1

Views: 1269

Answers (1)

Reid
Reid

Reputation: 4524

The service tag in my manifest was outside of my application tag.

Upvotes: 3

Related Questions