Rust
Rust
Download Image (JPG, GIF, etc.) to Base64
See more HTTP Examples
Demonstrates how to download an image, or any type of file, to get the data in base64 encoding format.Chilkat Rust Downloads
let mut success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
http.set_keep_response_body(true);
let bd = chilkat::BinData::new();
success = http.download_bd("https://www.chilkatsoft.com/images/starfish.jpg", &bd).is_ok();
let status_code = http.last_status();
if !success {
if status_code == 0 {
// Unable to either send the request or get the response.
println!("{}", http.last_error_text());
} else {
// We got a response, but the status code was not in the 200s
println!("Response status code: {}", status_code);
// Examine the response body.
println!("Response body:");
println!("{}", http.last_response_body());
}
println!("Download failed.");
} else {
println!("Download success, response status = {}", status_code);
let base64_image_data = bd.get_encoded("base64").unwrap_or_default();
println!("image data in base64 format:");
println!("{}", base64_image_data);
}