Java
Java
Demonstrate S3_UploadBytes
Demonstrates how to upload a file to the Amazon S3 service.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
http.put_AwsAccessKey("AWS_ACCESS_KEY");
http.put_AwsSecretKey("AWS_SECRET_KEY");
String bucketName = "chilkat.qa";
String objectName = "images/sea_creatures/starfish.jpg";
String localFilePath = "qa_data/jpg/starfish.jpg";
String contentType = "image/jpg";
CkBinData jpgData = new CkBinData();
success = jpgData.LoadFile(localFilePath);
if (!success) {
System.out.println("Failed to load " + localFilePath);
return;
}
CkByteData jpgBytes = new CkByteData();
success = jpgData.GetBinary(jpgBytes);
success = http.S3_UploadBytes(jpgBytes,contentType,bucketName,objectName);
if (success != true) {
System.out.println(http.lastErrorText());
return;
}
System.out.println("Success. File uploaded.");
}
}