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;
}
}