upload_file_options/
upload_file_options.rs1use baidu_netdisk_sdk::upload::SimpleUploadOptions;
2use baidu_netdisk_sdk::BaiduNetDiskClient;
3use log::info;
4
5#[tokio::main]
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 env_logger::init();
8
9 let client = BaiduNetDiskClient::builder().build()?;
10 info!("Client created successfully");
11
12 client.load_token_from_env()?;
13 info!("Token loaded successfully");
14
15 let args: Vec<String> = std::env::args().collect();
16
17 if args.len() < 3 {
18 println!(
19 "Usage: {} <local_file> <remote_path> [chunk_size] [concurrency]",
20 args[0]
21 );
22 println!("Example: {} test.mp4 /upload/video.mp4 8388608 20", args[0]);
23 println!(" - chunk_size: bytes per chunk (default: 4194304 = 4MB)");
24 println!(" - concurrency: parallel uploads (default: 10)");
25 return Ok(());
26 }
27
28 let local_file = &args[1];
29 let remote_path = &args[2];
30
31 let chunk_size: usize = args
32 .get(3)
33 .and_then(|s| s.parse().ok())
34 .unwrap_or(4 * 1024 * 1024);
35 let concurrency: usize = args.get(4).and_then(|s| s.parse().ok()).unwrap_or(10);
36
37 let options = SimpleUploadOptions::default()
38 .chunk_size(chunk_size)
39 .max_concurrency(concurrency);
40
41 println!("=== Baidu NetDisk File Upload (Custom Options) ===");
42 println!("Local file: {}", local_file);
43 println!("Remote path: {}", remote_path);
44 println!(
45 "Chunk size: {} bytes ({:.2} MB)",
46 chunk_size,
47 chunk_size as f64 / 1024.0 / 1024.0
48 );
49 println!("Concurrency: {}", concurrency);
50 println!();
51
52 let start_time = std::time::Instant::now();
53
54 let response = client
55 .upload()
56 .upload_file_with_options(local_file, remote_path, options)
57 .await?;
58
59 println!("File uploaded successfully!");
60 println!(" FS ID: {}", response.fs_id);
61 println!(" Path: {}", response.path);
62 println!(" Size: {} bytes", response.size);
63 println!(" Category: {}", response.category);
64 println!(" MD5: {}", response.md5.unwrap_or_default());
65 println!(" Upload time: {:?}", start_time.elapsed());
66
67 Ok(())
68}