【问题标题】:Android upload on aws s3 httpAndroid 在 aws s3 http 上上传
【发布时间】: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


    【解决方案1】:

    您使用的是非常过时的 SDK 版本。请升级到最新版本 2.16.6 并尝试使用此处的说明上传: https://aws-amplify.github.io/docs/sdk/android/storage#upload-a-file

    【讨论】:

    • 这个问题已经过去了 8 个月。
    • 我看到了,我意识到这现在可能甚至不相关,但由于这没有答案,我决定发布一些相关的内容。过去 8 个月发生了很多变化,但您的“2.2”版本甚至在 8 个月前就已经过时了 :)
    猜你喜欢
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 2014-09-29
    • 2012-11-07
    • 2021-04-26
    • 2018-07-12
    • 2017-04-12
    • 2015-01-10
    相关资源
    最近更新 更多