Upload a file to S3 using the AWS SDK

I am trying to upload a file to an Amazon S3 bucket using the AWS SDK.

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

}

However, this does not work; it causes an error when calling .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)
+5
source share
1 answer

I thought that since my application constantly edits this file and this fragment happens in a separate stream, the file actually changes before it is downloaded ... If I make a temporary copy of the file and load it into a bucket, it works.

+5
source

All Articles