upload/
upload.rs

1use flickr_api::*;
2use std::env;
3use std::error::Error;
4use std::io::{self, Write};
5use std::path::Path;
6
7fn prompt(message: &str) -> String {
8    // Create a new String to hold the user's input
9    let mut input = String::new();
10
11    // Print a prompt message to the console
12    print!("{message}");
13
14    // Ensure the prompt message is printed immediately
15    io::stdout().flush().ok();
16
17    // Read the user's input from standard input
18    io::stdin()
19        .read_line(&mut input)
20        .expect("Failed to read line");
21
22    // Remove the trailing newline character
23    input.trim().to_string()
24}
25
26#[tokio::main]
27async fn main() -> Result<(), Box<dyn Error>> {
28    let arg = env::args().nth(1).unwrap();
29    let path = Path::new(&arg);
30    println!("Uploading {path:?}");
31
32    let client = FlickrAPI::new(ApiKey {
33        key: prompt("API key: "),
34        secret: prompt("API secret: "),
35    })
36    .login()
37    .await?;
38
39    let id = client.photos().upload_from_path(&path).await?;
40    println!("Uploaded {path:?} and was given {id}");
41
42    Ok(())
43}