Android在aws s3 http上上传

问题描述 投票:0回答:1

我在上传的onError中有此问题:无法执行HTTP请求:写入错误:ssl = 0x7b4a65b280:系统调用期间I / O错误,对等方重置连接

我不知道为什么,我也遵循了指南。

清单中有<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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.