Java
Chilkat2 Java
Backblaze S3 Upload Binary
See more Backblaze S3 Examples
Demonstrates how to upload the in-memory binary data to an Backblaze bucket.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.BinData;
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();
// keyID = Access Key ID or Access Key
http.setAwsAccessKey("access-key");
// applicationKey = Secret Access Key or Secret Key
http.setAwsSecretKey("secret-key");
// Region is the 2nd part of your S3 Endpoint
http.setAwsEndpoint("s3.us-west-002.backblazeb2.com");
String bucketName = "chilkat-test-123";
String objectName = "starfish.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";
http.setKeepResponseBody(true);
BinData jpgData = new BinData();
jpgData.loadFile("qa_data/jpg/starfish.jpg");
try {
http.s3UploadBd(jpgData, contentType, bucketName, objectName);
System.out.println("JPG uploaded.");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
Xml xml = new Xml();
xml.loadXml(http.getLastResponseBody());
System.out.println(xml.getXml());
}
}
}