AWS SDK を使用して Amazon S3 バケットにファイルをアップロードしようとしています。
class LogToS3Bucket extends Thread{
public void run() {
super.run();
Gdx.app.log("msg", "secondThreadRunning yeahhhhh!");
File fileToPut = new File("../../../MyProject", "settings.txt");
String accessKey = "<accessKey>";
String secretKey = "<secretKey>";
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 conn = new AmazonS3Client(credentials);
conn.putObject("bucketname", "filename.txt", fileToPut);
}
}
ただし、動作しません。.putObject() の呼び出しでエラーがスローされます。
Exception in thread "Thread-1" Status Code: 400, AWS Service: Amazon S3, AWS Error Code: BadDigest, AWS Error Message: The Content-MD5 you specified did not match what we received.
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:614)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:312)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:165)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2951)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1123)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:979)
at com.myproject.LogToS3Bucket.run(LogToS3Bucket.java:22)