我在尝试在Android应用上传图片时出现此错误。这是我第一次使用AWS。
Unable to execute HTTP request: Write error: ssl=0x9f025e00: I/O error during system call, Connection reset by peer
javax.net.ssl.SSLException: Write error: ssl=0x9f025e00: I/O error during system call, Connection reset by peer
我创建了一个帐户,一个Bucket,一个Cognito Identity Pool。
public class SaveProfilePictureOnAWSS3 extends AsyncTask<String, Void, Void> {
@Override
public Void doInBackground(String... params) {
try {
String picture_url = params[0];
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
App.getInstance().getApplicationContext(), // Application Context
App.getInstance().getResources().getString(R.string.AWS_IdentityPoolId), // Identity Pool ID
Regions.EU_WEST_1 // Region enum
);
AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider);
File fileToUpload = new File(picture_url);
PutObjectRequest putRequest = new PutObjectRequest("millezimu", MilleZimU.getInstance().getUserInstance().getId(), fileToUpload);
PutObjectResult putResponse = s3Client.putObject(putRequest);
} catch (Exception e) {
EventBus.getDefault().post(new MessageToDisplayEvent(e.getMessage(), true));
}
return null;
}
或与此:
TransferUtility transferUtility = AWSUtils.getTransferUtility(MilleZimU.getInstance());
TransferObserver observer = transferUtility.upload("millezimu",
MilleZimU.getInstance().getUserInstance().getId(), fileToUpload);
但仍然收到错误!
答案 0 :(得分:2)
问题发生的原因是客户区域没有设置!!!
将区域添加到Amazon Demo中提供的帮助程序后,它可以正常工作。
/**
* Gets an instance of a S3 client which is constructed using the given
* Context.
*
* @param context An Context instance.
* @return A default S3 client.
*/
public static AmazonS3Client getS3Client(Context context) {
if (sS3Client == null) {
sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext()));
sS3Client.setRegion(Region.getRegion(Regions.EU_CENTRAL_1));
}
return sS3Client;
}