Java
Chilkat2 Java
S3 Upload File
See more Amazon S3 Examples
Demonstrates how to upload a file to the Amazon S3 service.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat 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";
// The Content-Type has the form type/subtype, such as application/pdf, application/json, image/jpeg, etc.
// See Explaining Content-Types
String contentType = "image/jpeg";
try {
http.s3UploadFile(localFilePath, contentType, bucketName, objectName);
System.out.println("File uploaded.");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
}
}
}