Skip to main content

SimpleUploadOptions

Struct SimpleUploadOptions 

Source
pub struct SimpleUploadOptions {
    pub chunk_size: usize,
    pub max_concurrency: usize,
    pub type: i32,
}
Expand description

Options for simple upload methods

Use the builder pattern to customize upload behavior:

§Example

use baidu_netdisk_sdk::upload::SimpleUploadOptions;

let options = SimpleUploadOptions::default()
    .chunk_size(8 * 1024 * 1024)  // 8MB chunks
    .max_concurrency(20)         // 20 parallel uploads
    .r#type(1);                  // file type

§Default Values

  • chunk_size: 4MB (4194304 bytes)
  • max_concurrency: 10
  • r#type: 1

Fields§

§chunk_size: usize

Size of each chunk in bytes (default: 4MB)

§max_concurrency: usize

Maximum number of parallel chunk uploads (default: 10)

§type: i32

File type hint (default: 1)

Implementations§

Source§

impl SimpleUploadOptions

Source

pub fn new() -> Self

Source

pub fn chunk_size(self, size: usize) -> Self

Examples found in repository?
examples/upload_file_options.rs (line 38)
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}
Source

pub fn max_concurrency(self, concurrency: usize) -> Self

Examples found in repository?
examples/upload_file_options.rs (line 39)
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}
Source

pub fn type(self, type: i32) -> Self

Trait Implementations§

Source§

impl Clone for SimpleUploadOptions

Source§

fn clone(&self) -> SimpleUploadOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SimpleUploadOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SimpleUploadOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more