2017-02-09 171 views
-2

我想將圖像上傳到我的s3存儲桶。我嘗試了不同的解決方案來上傳文件,如this tutorial,但我總是得到錯誤的SSL例外:將Android文件上傳到Amazon S3

Unable to execute HTTP request: Write error: ssl=0x55a53d5240: I/O error during system call, Connection reset by peer

我發現有關此異常的評論一個評論是,如果你的網絡不好,你可以在錯誤得到。但我的網絡很好。

我的代碼如下:

private void uploadImage() { 

    // Initialize the Amazon Cognito credentials provider 
    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
      getContext().getApplicationContext(), 
      "us-west-2:************", // Identity Pool ID 
      Regions.US_WEST_2 // Region 
    ); 


    ClientConfiguration configuration = new ClientConfiguration(); 
    configuration.setConnectionTimeout(50000); 
    configuration.setSocketTimeout(300000); 

    final AmazonS3 s3 = new AmazonS3Client(credentialsProvider, configuration); 

    TransferUtility transferUtility = new TransferUtility(s3, getContext().getApplicationContext()); 

    LocalImage image = mAddImageAdapter.getLocalImage(0); 
    final File mFile = new File(image.getImagePath()); 
    long len = mFile.length(); 

    transferUtility.upload("2y1s-images", mFile.getName(), mFile).setTransferListener(new TransferListener() { 
     @Override 
     public void onStateChanged(int id, TransferState state) { 

      Log.i(TAG, "image upload state: " + state.name()); 
     } 

     @Override 
     public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) { 


      Log.e(TAG, "image upload percentage: " + bytesCurrent + " -" + bytesTotal); 
     } 

     @Override 
     public void onError(int id, Exception ex) { 

      Log.e(TAG, "image upload error: " + ex.getMessage()); 
     } 
    }); 


} 
+0

只是檢查 - 您是否記得在您的清單中添加互聯網許可? – SteelBytes

+0

是的,我有互聯網,讀取和寫入權限 – gokhan

+0

哪些版本的aws sdk你使用? (最新的?) – SteelBytes

回答

0

我發現花了2天之後異常的原因。 ssl例外的主要原因是我在不同地區的認證憑證和s3桶。我希望這個答案有助於其他人。

相關問題