我正在尝试使用 AWS 开发工具包将文件上传到 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)