Sample code for 30+ languages & platforms
Rust

S3 Delete File

See more Amazon S3 Examples

Demonstrates how to delete a remote file (object) on the Amazon S3 service.

Chilkat Rust Downloads

Rust

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

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

// Insert your access key here:
http.set_aws_access_key("AWS_ACCESS_KEY");

// Insert your secret key here:
http.set_aws_secret_key("AWS_SECRET_KEY");

let bucket_name = "chilkattest".to_string();
let object_name = "starfish.jpg".to_string();

http.set_keep_response_body(true);

if http.s3_delete_object(&bucket_name, &object_name).is_err() {
    println!("{}", http.last_error_text());
    return;
}

if http.last_status() != 204 {
    println!("Status code = {}", http.last_status());
    println!("{}", http.last_response_body());
    println!("Failed.");
    return;
}

// 204 is the success response status.
// When successful, the response body will be empty.
println!("Status code = {}", http.last_status());
println!("Success. Object deleted.");