I get this error, when try to upload a picture on my Android app. This is the first time I'm working with 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
I have create a Account, a Bucket, a 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;
}
or with this :
TransferUtility transferUtility = AWSUtils.getTransferUtility(MilleZimU.getInstance());
TransferObserver observer = transferUtility.upload("millezimu",
MilleZimU.getInstance().getUserInstance().getId(), fileToUpload);
but still get the error !
The problem happen because the region of the client was not set !!!
After adding the region to the helper provided in Amazon Demo, it works.
/**
* 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.