出现"content-MD5"错误.在AWS s3存储桶上 [英] Error with "content-MD5" on AWS s3 bucket
问题描述
我正在创建一个应用程序,该应用程序将视频文件发送到Amazon s3存储桶,但只能发送1个视频,然后必须将apk重新上传到手机.引发的错误与服务上的"BadDigest"错误有关:"Amazon S3".以下是输出错误.
I am creating an application that sends a video file to an Amazon s3 bucket but can only send 1 video before having to re-upload the apk to the phone. The error being thrown has something to do with a "BadDigest" error on the service: "Amazon S3". Below is the output error.
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)
如果您需要更多信息,请告诉我,这是一个时间敏感的问题.
Please let me know if you need further information, this is a fairly time sensitive question.
编辑1 作为对donkon的响应,这是我用来将文件发送到服务器的代码:
EDIT 1 In response to donkon, here is the code that I am using to send my files to the server:
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);
}
}
推荐答案
问题是内容在上载时正在更改.尝试使用您的代码上传静态文件(即已完成录制的视频),它应该可以正常工作.
The issue is that the content is changing as you are uploading it. Try using your code to upload a static file (I.e. a video that is done recording) and it should work.
这篇关于出现"content-MD5"错误.在AWS s3存储桶上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!