【发布时间】:2019-09-09 15:09:30
【问题描述】:
我在上传的onError中出现这个问题:无法执行HTTP请求:写入错误:ssl=0x7b4a65b280:系统调用时出现I/O错误,连接被peer重置
我不知道为什么,我也遵循了指导方针。
我在清单中有<service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />
我在内部 gradle 中有 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());
}
});
}
【问题讨论】:
标签: android amazon-web-services http amazon-s3 upload