Android 在amazon s3上上传图像显示TransferUtility尚未配置默认的存储桶

Android 在amazon s3上上传图像显示TransferUtility尚未配置默认的存储桶,android,amazon-s3,Android,Amazon S3,我正在尝试将相机或多媒体资料图像上载到amazon s3。我有存储桶名称、访问密钥、密钥、文件名和位置。请使用这些凭据帮助我在amazon s3上上载图像。我遇到以下异常。请帮助我 java.lang.IllegalArgumentException: TransferUtility has not been configured with a default bucket. Please use the corresponding method that specifies bucket na

我正在尝试将相机或多媒体资料图像上载到amazon s3。我有存储桶名称、访问密钥、密钥、文件名和位置。请使用这些凭据帮助我在amazon s3上上载图像。我遇到以下异常。请帮助我

java.lang.IllegalArgumentException: TransferUtility has not been configured with a default bucket. Please use the corresponding method that specifies bucket name or configure the default bucket name in construction of the object. See TransferUtility.builder().defaultBucket() or TransferUtility.builder().awsConfiguration()
这是我的密码

///////////////////////////////////////UPLOAD TO S3 WITH KEY AND SECRETKEY///////////////////
        // KEY and SECRET are gotten when we create an IAM user above
        AWSCredentials.S3KEY = AWSCredentials.S3KEY.replace("city", cityName);
        AWSCredentials.S3KEY = AWSCredentials.S3KEY.replace("type", entityType);
        AWSCredentials.S3KEY = AWSCredentials.S3KEY.replace("entityid", mallId);
        AWSCredentials.S3KEY = AWSCredentials.S3KEY.replace("fileName", Common.imageName);
        Log.d("S3 KEY", AWSCredentials.S3KEY);

        BasicAWSCredentials credentials = new BasicAWSCredentials(AWSCredentials.KEY, AWSCredentials.SECRET);
        AmazonS3Client s3Client = new AmazonS3Client(credentials);
        s3Client.putObject(new PutObjectRequest(AWSCredentials.BUCKET_NAME, AWSCredentials.KEY, new File(Common.imageLocation)));
        //s3Client.setBucketAccelerateConfiguration(AWSCredentials.BUCKET_NAME);
        //s3Client.setEndpoint("https://s3.ap-south-1.amazonaws.com/lipl-media/");
        TransferUtility transferUtility = TransferUtility.builder()
                .context(getApplicationContext())
                .awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
                .s3Client(s3Client)
                .build();

/*try
{
    // FileInputStream fis = new FileInputStream(new 
 File(Common.imageName));
}
 catch(FileNotFoundException e)
{
e.printStackTrace();
 }*/
             TransferObserver uploadObserver =
                transferUtility.upload(AWSCredentials.S3KEY, new File(Common.imageLocation));

        uploadObserver.setTransferListener(new TransferListener() {

            @Override
            public void onStateChanged(int id, TransferState state) {
                if (TransferState.COMPLETED == state) {
                    //Toast.makeText(FormBuilderActivity.this,"Upload Status:"+state.toString(),Toast.LENGTH_SHORT).show();
                    Log.d("S3 upload status", state.toString());
                    // Handle a completed download.
                }
            }

            @Override
            public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
                float percentDonef = ((float)bytesCurrent/(float)bytesTotal) * 100;
                int percentDone = (int)percentDonef;
            }

            @Override
            public void onError(int id, Exception ex) {
                //Toast.makeText(FormBuilderActivity.this,"Upload Error:"+ex.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
                Log.d("S3 upload fail", ex.getLocalizedMessage());
                ex.printStackTrace();
                // Handle errors
            }

        });
 // If your upload does not trigger the onStateChanged method inside your
 // TransferListener, you can directly check the transfer state as shown here.
        if (TransferState.COMPLETED == uploadObserver.getState()) {
            Log.d("S3 upload status", uploadObserver.getState().toString());
            //Toast.makeText(FormBuilderActivity.this,"Upload Status:"+uploadObserver.getState().toString(),Toast.LENGTH_SHORT).show();
 // Handle a completed upload.
        }

下面的行是导致错误的原因

TransferObserver uploadObserver =
                transferUtility.upload(AWSCredentials.S3KEY, new File(Common.imageLocation));
这是因为没有为
TransferUtility
实例指定目标存储桶。相反,请使用下面的代码,这是TransferUtility类的另一个构造函数,其中bucket作为参数传入

TransferObserver uploadObserver =
                transferUtility.upload(YOUR_BUCKET_NAME, AWSCredentials.S3KEY, new File(Common.imageLocation));

下面的行是导致错误的原因

TransferObserver uploadObserver =
                transferUtility.upload(AWSCredentials.S3KEY, new File(Common.imageLocation));
这是因为没有为
TransferUtility
实例指定目标存储桶。相反,请使用下面的代码,这是TransferUtility类的另一个构造函数,其中bucket作为参数传入

TransferObserver uploadObserver =
                transferUtility.upload(YOUR_BUCKET_NAME, AWSCredentials.S3KEY, new File(Common.imageLocation));