{"action":"closed","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-android/issues/94","repository_url":"https://api.github.com/repos/aws/aws-sdk-android","labels_url":"https://api.github.com/repos/aws/aws-sdk-android/issues/94/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-android/issues/94/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-android/issues/94/events","html_url":"https://github.com/aws/aws-sdk-android/issues/94","id":131567285,"number":94,"title":"Upload files to S3 fails","user":{"login":"devgutt","id":1953811,"avatar_url":"https://avatars.githubusercontent.com/u/1953811?v=3","gravatar_id":"","url":"https://api.github.com/users/devgutt","html_url":"https://github.com/devgutt","followers_url":"https://api.github.com/users/devgutt/followers","following_url":"https://api.github.com/users/devgutt/following{/other_user}","gists_url":"https://api.github.com/users/devgutt/gists{/gist_id}","starred_url":"https://api.github.com/users/devgutt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devgutt/subscriptions","organizations_url":"https://api.github.com/users/devgutt/orgs","repos_url":"https://api.github.com/users/devgutt/repos","events_url":"https://api.github.com/users/devgutt/events{/privacy}","received_events_url":"https://api.github.com/users/devgutt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aws/aws-sdk-android/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2016-02-05T06:26:52Z","updated_at":"2016-04-04T17:56:11Z","closed_at":"2016-04-04T17:56:11Z","body":"When I upload a file bigger than 200kb for the first time, using TransferUtility, I received the follow error, and the file fails to upload.\r\n\r\n```\r\nI/AmazonHttpClient: Unable to execute HTTP request: Write error: ssl=0xb73cbbf8: I/O error during system call, Connection reset by peer\r\njavax.net.ssl.SSLException: Write error: ssl=0xb73cbbf8: I/O error during system call, Connection reset by peer\r\n    at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)\r\n    at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:740)\r\n    at com.android.okio.Okio$1.write(Okio.java:70)\r\n    at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)\r\n    at com.android.okio.RealBufferedSink.write(RealBufferedSink.java:44)\r\n    at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:287)\r\n    at com.android.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:116)\r\n    at com.android.okio.RealBufferedSink$1.write(RealBufferedSink.java:131)\r\n    at com.amazonaws.http.UrlHttpClient.write(UrlHttpClient.java:172)\r\n    at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:129)\r\n    at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:65)\r\n    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:353)\r\n    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:196)\r\n    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4212)\r\n    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1619)\r\n    at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:194)\r\n    at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:76)\r\n    at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:41)\r\n    at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)\r\n    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)\r\n    at java.lang.Thread.run(Thread.java:818)` \r\n```\r\n\r\nBut If I try to upload a file smaller than 200kb, the upload works just fine. The upload also works if I START to upload using the smaller file and than upload the bigger ones. \r\n\r\nI'm using AWS SDK 2.2.11 and I tested and found this same behavior in the android sample (https://github.com/awslabs/aws-sdk-android-samples - S3TransferUtilitySample).\r\n\r\nThis is happening ONLY on my device running Android 5.0.2 (Moto G 2).\r\nI tested in other devices and emulators, but didn't find any error on those: \r\n\r\n- Android 4.1.1 (Device Prism II) -> OK\r\n- Android 4.4.2 (emulator x86) -> OK\r\n- Android 5.0.2 (emulator x86) -> OK\r\n\r\nI tried to change the timeout and the protocol (https and http), but didn't work either.\r\nI did all the tests on Wi-Fi (internet very stable).\r\n\r\nThe location of the bucket seems irrelevant, because the upload works, if I don't upload the first file bigger than 200kb.\r\n\r\nAs workaround, I'm uploading a 1kb file, prior any upload, but it's obviously not the correct solution:\r\n```\r\n    public static TransferUtility getTransferUtility(Context context) {\r\n        if (sTransferUtility == null) {\r\n            String bucketName = context.getResources().getString(R.string.AWS_S3_BUCKET);\r\n\r\n            sTransferUtility = new TransferUtility(getS3Client(context.getApplicationContext()),\r\n                    context.getApplicationContext());\r\n\r\n            /////////////////////////////////////\r\n            /* BUG FIX - START */\r\n            //Bug fix for lollipop devices (not emulator)\r\n            //First file bigger than 200Kb doesn't work (only device lollipop, kitkat, kellybeans ok)\r\n\r\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\r\n                String filename = \"xfile\";\r\n                File file = new File(context.getFilesDir(), filename);\r\n                try {\r\n                    FileOutputStream stream = new FileOutputStream(file);\r\n                    stream.write(\"G\".getBytes());\r\n                    stream.close();\r\n                    sTransferUtility.upload(bucketName, file.getName(), file);\r\n\r\n                } catch (IOException e) {\r\n                    e.printStackTrace();\r\n                }\r\n            }\r\n            /* END BUG FIX */\r\n            ////////////////////////////////////\r\n        }\r\n\r\n        return sTransferUtility;\r\n    }\r\n```\r\n\r\nAny help would be really appreciated."}}