Rust
Rust
Google Cloud Storage: Update Object Metadata
See more Google Cloud Storage Examples
Demonstrates how to update (edit) the metadata associated with an object in a Google Cloud Storage bucket.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Implements the following CURL command:
// curl -X PATCH --data-binary @JSON_FILE_NAME \
// -H "Authorization: Bearer OAUTH2_TOKEN" \
// -H "Content-Type: application/json" \
// "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let bd_request_body = chilkat::BinData::new();
if bd_request_body.load_file("JSON_FILE_PATH").is_err() {
println!("Failed to load JSON_FILE_PATH");
return;
}
// Adds the "Authorization: Bearer OAUTH2_TOKEN" header.
http.set_auth_token("OAUTH2_TOKEN");
let resp = chilkat::HttpResponse::new();
if http.http_bd("PATCH", "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME", &bd_request_body, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}