【问题标题】:Getting SSL Exception with trying upload to AWS s3尝试上传到 AWS s3 时出现 SSL 异常
【发布时间】:2016-01-23 11:52:42
【问题描述】:

尝试在我的 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

我创建了一个帐户、一个存储桶、一个 Cognito 身份池。

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);

但还是报错!

【问题讨论】:

  • 请提供代码以重现和完整的堆栈跟踪。

标签: android ssl amazon-web-services amazon-s3


【解决方案1】:

这个问题是因为没有设置客户端的区域!!!

将区域添加到 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;
}

【讨论】:

  • 很高兴您解决了问题,但奇怪的是该区域会导致 SSL 问题。
猜你喜欢
  • 2016-07-24
  • 1970-01-01
  • 2021-12-25
  • 2011-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-16
相关资源
最近更新 更多