Getting Error while Uploading Media to S3 Bucket from android

Snehangshu Kar :

I am using android aws dependency com.amazonaws:aws-android-sdk-s3:2.6.+

While uploading Image getting error as bellow

com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: XXXXXXXXXXX), S3 Extended Request ID:XXXXXXXXXXXX

Here is the Code for uploading Image

 private void beginUpload(String filePath, final String mediaCaption, 
 Message message,boolean isThumb,final 
 UploadFileToStorageCompletionListener listener) {
    getLogger().log(Strings.TAG, "########## 3:  " + filePath);
    //construct a bucket path
    final String fullBucketPath = 
 constructBucketPath(message.getMediaType(), message.getId(), 
 isThumb);
    File file = new File(filePath);
    mObserver = mTransferUtility.upload(fullBucketPath, mediaCaption, 
   file);

    mObserver.setTransferListener(new TransferListener() {
        @Override
        public void onStateChanged(int id, TransferState state) {
            getLogger().log(Strings.TAG," onStateChanged() " + state);
            if (state.equals(TransferState.COMPLETED)) {
                listener.onUploadSuccess(fullBucketPath);
            }
        }

        @Override
        public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
            getLogger().log(Strings.TAG,"onProgressChanged() " + bytesCurrent + "/" + bytesTotal);
            dismissProgressDialog();
        }

        @Override
        public void onError(int id, Exception ex) {
            listener.onDatabaseError(new FirebaseFailure(ex));
            getLogger().log(Strings.TAG, "onError() " + ex.getMessage());
        }
    });
}
Shavareppa :

First, need to check the permissions for the s3 bucket. And go to the bucket policy and check the json object which is permissions for put, get and post.

 {
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "AddPerm",
        "Effect": "Allow",
        "Principal": "*",
        "Action": [
            "s3:PutObject",
            "s3:GetObject"
        ],
        "Resource": "arn:aws:s3:::{FILE NAME}/*"
    }
]
}

Try the above permissions.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=110118&siteId=1