Sanjay Ghadiya
Sanjay Ghadiya

Reputation: 151

Amazon S3 Upload issue Android SDK, com.amazonaws.AmazonClientException: More data read (4567265) than expected (4561427)

When I upload file from Nexus 6 using amazon s3 SDK some time it throws me com.amazonaws.AmazonClientException: More data read (4567265) than expected (4561427) exception.

But when I upload image from Moto G4 plus with same code it will uploaded every time.

Please help me in solving this issue.

Here is my code for reference:

 private void uploadingScreenshot(String filePath) 
    {
        File file = new File(filePath);
        if (file.exists()) {
            final String serverPath = S3Util.getMediaPath(Utility.MediaType.SCREENSHOT, false, "");
            ObjectMetadata meta = new ObjectMetadata();
            meta.setContentLength(file.length());
            S3Util.uploadMedia(SharedFolderDetailActivity.this, file, serverPath, meta, new TransferListener() {
                @Override
                public void onStateChanged(int id, TransferState state) {
                    switch (state) {
                        case COMPLETED: {
                            String path = S3Constants.BUCKET_URL + serverPath;
                            callTookScreenshotNotifierWS(path);
                        }
                        break;
                    }
                }

                @Override
                public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {

                }

                @Override
                public void onError(int id, Exception ex) {
                    if (ex != null)
                        Log.e(TAG, ex.getMessage());
                }
            });
        }
    }

This function is used to upload file on amazon s3 server.

 public class S3Util {

        public static TransferObserver uploadMedia(final Context context, File file, String s3Path, ObjectMetadata objectMetadata, TransferListener l) {
            TransferObserver observer = getTransferUtility(context).upload(S3Constants.BUCKET_NAME, s3Path, file,objectMetadata);
            observer.setTransferListener(l);
            return observer;
        }
    }

Upvotes: 15

Views: 1107

Answers (2)

Scrobot
Scrobot

Reputation: 1981

My opinion is, that there is something compatibility problem with aws-sdk and android sdk. The best way, is try to downgrade your aws-version and find out more stable version with your android sdk. Maybe I'm wrong..

Also, I recommend you to write issue in https://github.com/aws/aws-sdk-android/issues

I hope that you will be able to solve your problem. Good Luck!)

Upvotes: 0

Kousei
Kousei

Reputation: 1291

try this answer AmazonClientException: Data read has a different length than the expected

I have also faced this problem previously, hopefully, this may help you

Upvotes: 1

Related Questions