San*_*iya 15 upload android file-upload amazon-s3
当我使用amazon s3 SDK从Nexus 6上传文件时,它会抛出com.amazonaws.AmazonClientException:更多数据读取(4567265)比预期(4561427)异常.
但是当我从Moto G4上传图像并使用相同的代码时,它每次都会上传.
请帮我解决这个问题.
这是我的代码供参考:
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());
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
此功能用于在amazon s3服务器上传文件.
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
418 次 |
| 最近记录: |