Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

VoiceBase -- Upload a media file for transcription and analysis

See more VoiceBase Examples

This example demonstrates how to upload a media file for transcription and analysis. It duplicates the following curl command:
curl https://apis.voicebase.com/v2-beta/media \
  --form media=@msg_123_abc.wav \
  --header "Authorization: Bearer ${TOKEN}"

Chilkat Rust Downloads

Rust

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

// Insert your Bearer token here:
let access_token = "VOICEBASE_TOKEN".to_string();

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

let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_path("/v2-beta/media");
req.set_content_type("multipart/form-data");

// Add the access (bearer) token to the request, which is a header
// having the following format:
// Authorization: Bearer <userAccessToken>
let sb_auth = chilkat::StringBuilder::new();
let _ = sb_auth.append("Bearer ");
let _ = sb_auth.append(&access_token);
req.add_header("Authorization", &sb_auth.get_as_string().unwrap_or_default());

if req.add_file_for_upload2("media", "qa_data/wav/msg_123_abc.wav", "audio/x-wav").is_err() {
    println!("{}", req.last_error_text());
    return;
}

let resp = chilkat::HttpResponse::new();
if http.http_s_req("apis.voicebase.com", 443, true, &req, &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

// Examine the response status code and body.
println!("Response status code = {}", resp.status_code());

// The response should be JSON, even if an error.
let json = chilkat::JsonObject::new();
let _ = json.load(&resp.body_str());
json.set_emit_compact(false);

println!("{}", json.emit().unwrap_or_default());

// A successful response will have a status code = 200
if resp.status_code() != 200 {
    println!("Failed.");
} else {
    println!("mediaId: {}", json.string_of("mediaId").unwrap_or_default());
    println!("href: {}", json.string_of("_links.self.href").unwrap_or_default());
    println!("status: {}", json.string_of("status").unwrap_or_default());
    println!("Success.");
}

// Here is an example of a successful response:

// 	{ 
// 	  "_links": { 
// 	    "self": { 
// 	      "href": "/v2-beta/media/856a1e85-c847-4c3c-b7a4-6cf15cd51db4"
// 	    }
// 	  },
// 	  "mediaId": "856a1e85-c847-4c3c-b7a4-6cf15cd51db4",
// 	  "status": "accepted",
// 	  "metadata": {}
// 	}