Sample code for 30+ languages & platforms
Java

S3 Upload a File with Public Read Permissions

See more Amazon S3 Examples

Demonstrates how to upload a file to the Amazon S3 service with the x-amz-acl request header set to "public-read" to allow the file to be publicly downloadable.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat HTTP API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        // Insert your AWS keys here:
        http.setAwsAccessKey("AWS_ACCESS_KEY");
        http.setAwsSecretKey("AWS_SECRET_KEY");

        String bucketName = "chilkat.ocean";
        String objectName = "seahorse.jpg";
        String localFilePath = "qa_data/jpg/seahorse.jpg";
        String contentType = "image/jpg";

        // Add the x-amz-acl request header to make the file publicly readable.
        http.setRequestHeader("x-amz-acl", "public-read");

        try {
            http.s3UploadFile(localFilePath, contentType, bucketName, objectName);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        if (http.getLastStatus() == 200) {
            System.out.println("File uploaded.");
        } else {
            System.out.println("Response status code: " + http.getLastStatus());
            System.out.println(http.getLastResponseBody());
        }
    }
}