我在上传的onError中存在此问题:无法执行HTTP请求:写入错误:ssl = 0x7b4a65b280:系统调用期间I / O错误,对等方重置连接
我不知道为什么,我也遵守了指南。
清单中有<service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />
我内部有implementation 'com.amazonaws:aws-android-sdk-s3:2.2.+'
我的代码:
public void upload(String path,File file) {
path=path.replace("/storage/emulated/0/blablabla/","");
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"blablabla", // Identity pool ID
Regions.EU_WEST_1 // Region
);
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext());
final TransferObserver observer = transferUtility.upload(
"blablabla", //this is the bucket name on S3
path, //this is the path and name
file //path to the file locally
);
observer.setTransferListener(new TransferListener() {
@Override
public void onStateChanged(int id, TransferState state) {
if (state.equals(TransferState.COMPLETED)) {
Log.d("AMAZON","si");
} else if (state.equals(TransferState.FAILED)) {
//Failed
Log.d("AMAZON","no");
}
}
@Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
}
@Override
public void onError(int id, Exception ex) {
Log.d("AMAZON",ex.getMessage());
}
});
}
答案 0 :(得分:0)
您使用的是SDK的过时版本。请升级到最新版本2.16.6,然后按照此处的说明尝试上传: https://aws-amplify.github.io/docs/sdk/android/storage#upload-a-file