Skip to main content

upload_bytes/
upload_bytes.rs

1use baidu_netdisk_sdk::BaiduNetDiskClient;
2use log::info;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6    env_logger::init();
7
8    let client = BaiduNetDiskClient::builder().build()?;
9    info!("Client created successfully");
10
11    client.load_token_from_env()?;
12    info!("Token loaded successfully");
13
14    let args: Vec<String> = std::env::args().collect();
15
16    let remote_path = if args.len() >= 2 {
17        &args[1]
18    } else {
19        "/upload/hello_bytes.txt"
20    };
21
22    println!("=== Baidu NetDisk Bytes Upload (Simple) ===");
23    println!("Remote path: {}", remote_path);
24    println!();
25
26    let test_data = b"Hello from upload_bytes! This is a simple byte array upload test.";
27    println!("Uploading {} bytes of data...", test_data.len());
28
29    let start_time = std::time::Instant::now();
30
31    let response = client.upload().upload_bytes(test_data, remote_path).await?;
32
33    println!("Bytes uploaded successfully!");
34    println!("  FS ID: {}", response.fs_id);
35    println!("  Server filename: {:?}", response.server_filename);
36    println!("  Path: {}", response.path);
37    println!("  Size: {} bytes", response.size);
38    println!("  Category: {}", response.category);
39    println!("  MD5: {}", response.md5.unwrap_or_default());
40    println!("  Upload time: {:?}", start_time.elapsed());
41
42    Ok(())
43}