发布whille上传到AWS S3存储桶

时间:2015-12-12 06:09:56

标签: android amazon-web-services amazon-s3 amazon-cognito awss3transfermanager

我正在尝试将图像文件上传到aws存储桶,但我在设备上有时会遇到此错误,

D/CognitoCachingCredentialsProvider: Identity id is changed
12-12 11:27:25.771 11239-14564/D/CognitoCachingCredentialsProvider: Saving identity id to SharedPreferences
12-12 11:27:25.771 11239-11246/com.amlooking4 I/dalvikvm: Jit: resizing JitTable from 4096 to 8192
12-12 11:27:26.161 11239-14564/D/CognitoCachingCredentialsProvider: Saving credentials to SharedPreferences

但过了一段时间后,它表现得像,

    I/AmazonHttpClient: Unable to execute HTTP request: SSL handshake timed out
                                                                      java.net.SocketTimeoutException: SSL handshake timed out

 Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x1e5dff8: Failure in SSL library, usually a protocol error
                                                                  error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:658 0x401d6cf5:0x00000000)
                                                                      at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
                                                                      at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:410)
                                                                        ... 23 more

已编辑:

现在我也得到了这个,

.parent-portlet

由于这种不当行为真的感到沮丧,代码是相同的,但有时候它执行得很好,有时它不会显示上面写的错误。

我是aws的新手,我明白它可以将认知识别保存到偏好中。

1 个答案:

答案 0 :(得分:2)

将此代码添加到Utils.Java

    private static CognitoCachingCredentialsProvider getCredProvider(Context context) {
    if (sCredProvider == null) {
        ClientConfiguration clientConfiguration = new ClientConfiguration();
        clientConfiguration.setConnectionTimeout(30000);
        clientConfiguration.setSocketTimeout(30000);
        sCredProvider = new CognitoCachingCredentialsProvider(
                context.getApplicationContext(),
                Constants.COGNITO_POOL_ID,
                Regions.fromName(Constants.COGNITO_POOL_REGION),clientConfiguration);
    }
    return sCredProvider;
};    

并且amazonS3Client假设看起来像这样:

     public static AmazonS3Client getS3Client(Context context) {
    if (sS3Client == null) {
        sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext()));
        sS3Client.setRegion(Region.getRegion(Regions.fromName(Constants.BUCKET_REGION)));

    }
    return sS3Client;
};