Rust
Rust
S3 Delete Bucket Object
See more Amazon S3 (new) Examples
Deletes an object in a bucket.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = chilkat::Rest::new();
// Connect to the Amazon AWS REST server.
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
let _ = rest.connect("s3.amazonaws.com", port, b_tls, b_auto_reconnect).is_ok();
// ----------------------------------------------------------------------------
// Important: For buckets created in regions outside us-east-1,
// there are three important changes that need to be made.
// See Working with S3 Buckets in Non-us-east-1 Regions for the details.
// ----------------------------------------------------------------------------
// Provide AWS credentials for the REST call.
let auth_aws = chilkat::AuthAws::new();
auth_aws.set_access_key("AWS_ACCESS_KEY");
auth_aws.set_secret_key("AWS_SECRET_KEY");
auth_aws.set_service_name("s3");
let _ = rest.set_auth_aws(&auth_aws).is_ok();
// Set the bucket name via the HOST header.
// In this case, the bucket name is "chilkat100".
rest.set_host("chilkat100.s3.amazonaws.com");
// This example deletes the object named "Abc.ics"
let sb_response = chilkat::StringBuilder::new();
if rest.full_request_no_body_sb("DELETE", "/Abc.ics", &sb_response).is_err() {
println!("{}", rest.last_error_text());
return;
}
// If successfully deleted, the response status code is 204 and the response body text will be empty.
let status_code = rest.response_status_code();
println!("Response status code = {}", status_code);
println!("Response text = ");
println!("{}", sb_response.get_as_string().unwrap_or_default());