Rust
Rust
Initiate Resumable Upload Session
See more Google Cloud Storage Examples
Initiate a Google Cloud Storage resumable upload session..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();
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/googleCloudStorage.json").is_err() {
println!("{}", json_token.last_error_text());
return;
}
let json_meta_data = chilkat::JsonObject::new();
let _ = json_meta_data.update_string("contentType", "image/jpeg");
// Adds the "Authorization: Bearer <access_token>" header..
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
let _ = http.set_url_var("bucket_name", "chilkat-bucket-b");
let _ = http.set_url_var("object_name", "penguins2.jpg");
let url = "https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", &url, &json_meta_data, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let status_code = resp.status_code();
println!("response status code = {}", status_code);
let mut session_url = String::new();
if status_code != 200 {
println!("{}", resp.body_str());
} else {
// The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
session_url = resp.get_header_field("Location").unwrap_or_default();
println!("Session URL = {}", session_url);
}