简体   繁体   中英

Android upload on aws s3 http

I have this problem in the onError of the upload: Unable to execute HTTP request: Write error: ssl=0x7b4a65b280: I/O error during system call, Connection reset by peer

I don't know why, also I've followed the guidelines.

I have <service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" /> in the manifest

I Have implementation 'com.amazonaws:aws-android-sdk-s3:2.2.+' in the internal gradle

My code:

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

You are on a really antiquated version of the SDK. Please upgrade to the latest version 2.16.6 and try uploading using the instruction here: https://aws-amplify.github.io/docs/sdk/android/storage#upload-a-file

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM