2017-11-11 38 views
0

我正在創建一個應用程序,它將視頻文件發送到Amazon s3存儲桶,但只能在將apk重新上傳到手機之前發送1個視頻。拋出的錯誤與服務上的「BadDigest」錯誤有關:「Amazon S3」。以下是輸出錯誤。AWS s3存儲桶上的「content-MD5」錯誤

11-08 23:56:33.805 26045-26045/org.----------.videorecorder_aws W/System.err: com.amazonaws.services.s3.model.AmazonS3Exception: The Content-MD5 you specified did not match what we received. (Service: Amazon S3; Status Code: 400; Error Code: BadDigest; Request ID: 3345945A95914871), S3 Extended Request ID: pSWjCNJ6sMOiFytjZr0PRn9rns3jFoMkECoI+lfXgF0agfQTY4CdvXlsYJbCBK9qYE/OoAkWTrY= 
11-08 23:56:33.806 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:729) 
11-08 23:56:33.806 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405) 
11-08 23:56:33.806 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212) 
11-08 23:56:33.806 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4625) 
11-08 23:56:33.807 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1728) 
11-08 23:56:33.807 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:214) 
11-08 23:56:33.807 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:88) 
11-08 23:56:33.807 26045-26045/org.----------.videorecorder_aws W/System.err:  at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:47) 
11-08 23:56:33.807 26045-26045/org.----------.videorecorder_aws W/System.err:  at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
11-08 23:56:33.808 26045-26045/org.----------.videorecorder_aws W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
11-08 23:56:33.808 26045-26045/org.----------.videorecorder_aws W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
11-08 23:56:33.808 26045-26045/org.----------.videorecorder_aws W/System.err:  at java.lang.Thread.run(Thread.java:762) 

請讓我知道如果您需要更多信息,這是一個相當時間敏感的問題。

編輯1 針對donkon,這裏要說的是,我使用我的文件發送到服務器的代碼:

public void submitVideoToS3Bucket(){ 
    TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext()); 

    File directory = new File(getFilesDir(), "Reflex"); 
    final File CameraFile = new File(directory, "camera-temp.mp4"); 

    Date now = new Date(); 
    String videoName = now.toString().concat(".mp4").replace(" ", "_").replace(":", ""); 

    TransferObserver observer = transferUtility.upload(Constants.BUCKET_NAME, videoName, CameraFile); 

    observer.setTransferListener(new TransferListener() { 

     @Override 
     public void onStateChanged(int id, TransferState state) { 
      if (TransferState.COMPLETED == state) { 
      } 
      System.out.println("state change"); 
     } 

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

     @Override 
     public void onError(int id, Exception ex) { 
      ex.printStackTrace(); 
     } 
    }); 
    if (TransferState.COMPLETED == observer.getState()) { 
     // Handle a completed upload. 
     Intent cameraIntent = new Intent(this, CameraActivity.class); 
     startActivity(cameraIntent); 
    } 
} 
+0

不知道,但是如果您還沒有,也應該在AWS論壇上發帖。如果您能負擔得起,AWS支持也非常好。 – nasch

+0

你能提供代碼和示例文件來重現錯誤嗎?你使用哪個版本的SDK? – donkon

+0

內容是否隨着您的上傳而改變? –

回答

0

的問題是,當你上傳的內容是不斷變化的。嘗試使用您的代碼上傳靜態文件(即,完成錄製的視頻),它應該可以工作。

+0

當我將「public void submitVideoToS3Bucket()」更改爲「public static ...」時,它不再有效。我該如何改變它,以便它上傳一個靜態文件? –

+0

在開始上傳之前,視頻必須完全錄制並保存。 –