Java
Chilkat2 Java
Wasabi Upload String
See more Wasabi Examples
Demonstrates how to upload the contents of a string to create an object in a Wasabi bucket.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.Xml;
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 access key here:
http.setAwsAccessKey("access-key");
// Insert your secret key here:
http.setAwsSecretKey("secret-key");
http.setAwsEndpoint("s3.wasabisys.com");
String bucketName = "chilkattest";
String objectName = "orchard.json";
String contentType = "application/json";
http.setKeepResponseBody(true);
// Let's say we have JSON in a string and want to upload it to a file in Wasabi..
String jsonStr = "{ \"orchard\": \"apple\" }";
// The charset indicates the byte representation of what is uploaded.
// If needed, Chilkat will internally convert to the desired byte representation before uploading.
String charset = "utf-8";
try {
http.s3UploadString(jsonStr, charset, contentType, bucketName, objectName);
System.out.println("String uploaded.");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
Xml xml = new Xml();
xml.loadXml(http.getLastResponseBody());
System.out.println(xml.getXml());
}
}
}