Sample code for 30+ languages & platforms
Rust

Backblaze S3 Upload Binary

See more Backblaze S3 Examples

Demonstrates how to upload the in-memory binary data to an Backblaze bucket.

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

// keyID = Access Key ID or Access Key
http.set_aws_access_key("access-key");

// applicationKey = Secret Access Key or Secret Key
http.set_aws_secret_key("secret-key");

// Region is the 2nd part of your S3 Endpoint
http.set_aws_endpoint("s3.us-west-002.backblazeb2.com");

let bucket_name = "chilkat-test-123".to_string();
let object_name = "starfish.jpg".to_string();

// The Content-Type has the form  type/subtype, such as application/pdf, application/json, image/jpeg, etc.
// See Explaining Content-Types
let content_type = "image/jpeg".to_string();

http.set_keep_response_body(true);

let jpg_data = chilkat::BinData::new();
let _ = jpg_data.load_file("qa_data/jpg/starfish.jpg").is_ok();

if http.s3_upload_bd(&jpg_data, &content_type, &bucket_name, &object_name).is_err() {
    println!("{}", http.last_error_text());

    let xml = chilkat::Xml::new();
    let _ = xml.load_xml(&http.last_response_body());
    println!("{}", xml.get_xml().unwrap_or_default());
} else {
    println!("JPG uploaded.");
}