AWS s3存储桶上的“content-MD5”出错

时间:2017-11-11 18:04:06

标签: java android amazon-web-services amazon-s3

我正在创建一个应用程序,它将视频文件发送到亚马逊s3存储桶,但只能在将apk重新上传到手机之前发送1个视频。抛出的错误与服务上的“BadDigest”错误有关:“Amazon S3”。以下是输出错误。

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

1 个答案:

答案 0 :(得分:0)

问题是内容在上传时会发生变化。尝试使用您的代码上传静态文件(即完成录制的视频),它应该可以工作。