pub struct PrecreateOptions {
pub path: String,
pub size: u64,
pub isdir: i32,
pub block_list: Vec<String>,
pub rtype: i32,
pub uploadid: Option<String>,
pub content_md5: Option<String>,
pub slice_md5: Option<String>,
pub local_ctime: Option<u64>,
pub local_mtime: Option<u64>,
}Expand description
Options for precreate upload
Fields§
§path: StringRemote file path on Baidu NetDisk
size: u64File size in bytes
isdir: i32Is directory (0 for file, 1 for directory)
block_list: Vec<String>List of block MD5s (each block is typically 4MB)
rtype: i32Conflict resolution type (1=overwrite, 2=rename, 3=new copy)
uploadid: Option<String>Optional uploadid for resuming interrupted uploads
content_md5: Option<String>Optional content MD5 for entire file
slice_md5: Option<String>Optional slice MD5
local_ctime: Option<u64>Optional local creation time (timestamp)
local_mtime: Option<u64>Optional local modification time (timestamp)
Implementations§
Source§impl PrecreateOptions
impl PrecreateOptions
Sourcepub fn new(path: &str, size: u64, block_list: Vec<String>) -> Self
pub fn new(path: &str, size: u64, block_list: Vec<String>) -> Self
Create new PrecreateOptions with basic required fields
Examples found in repository?
examples/upload_precreate.rs (line 77)
43async fn main() -> Result<(), Box<dyn std::error::Error>> {
44 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
45
46 let client = BaiduNetDiskClient::builder().build()?;
47 info!("Client created successfully");
48
49 client.load_token_from_env()?;
50 info!("Token loaded successfully");
51
52 let args: Vec<String> = std::env::args().collect();
53
54 if args.len() < 3 {
55 println!("Usage: {} <local_file> <remote_path>", args[0]);
56 println!("Example: {} test.txt /apps/test/test.txt", args[0]);
57 return Ok(());
58 }
59
60 let local_file = &args[1];
61 let remote_path = &args[2];
62
63 println!("=== Baidu NetDisk Preupload Test ===");
64 println!("Local file: {}", local_file);
65 println!("Remote path: {}", remote_path);
66 println!();
67
68 let (file_size, block_list) = get_file_md5blocks(local_file, 4 * 1024 * 1024)?;
69 let file_md5 = calculate_md5(local_file)?;
70
71 println!("File size: {} bytes", file_size);
72 println!("File MD5: {}", file_md5);
73 println!("Block count: {}", block_list.len());
74 println!("Block list: {:?}", block_list);
75 println!();
76
77 let options = PrecreateOptions::new(remote_path, file_size, block_list)
78 .content_md5(&file_md5)
79 .rtype(1);
80
81 println!("Sending precreate request...");
82 match client.upload().precreate(options).await {
83 Ok(response) => {
84 println!("Precreate success!");
85 println!(" Upload ID: {}", response.uploadid);
86 println!(" Path: {:?}", response.path);
87 println!(" Return type: {}", response.return_type);
88 println!(" Block list to upload: {:?}", response.block_list);
89 }
90 Err(e) => {
91 println!("Precreate failed: {}", e);
92 }
93 }
94
95 Ok(())
96}Sourcepub fn rtype(self, rtype: i32) -> Self
pub fn rtype(self, rtype: i32) -> Self
Set conflict resolution type (1=overwrite, 2=rename, 3=new copy)
Examples found in repository?
examples/upload_precreate.rs (line 79)
43async fn main() -> Result<(), Box<dyn std::error::Error>> {
44 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
45
46 let client = BaiduNetDiskClient::builder().build()?;
47 info!("Client created successfully");
48
49 client.load_token_from_env()?;
50 info!("Token loaded successfully");
51
52 let args: Vec<String> = std::env::args().collect();
53
54 if args.len() < 3 {
55 println!("Usage: {} <local_file> <remote_path>", args[0]);
56 println!("Example: {} test.txt /apps/test/test.txt", args[0]);
57 return Ok(());
58 }
59
60 let local_file = &args[1];
61 let remote_path = &args[2];
62
63 println!("=== Baidu NetDisk Preupload Test ===");
64 println!("Local file: {}", local_file);
65 println!("Remote path: {}", remote_path);
66 println!();
67
68 let (file_size, block_list) = get_file_md5blocks(local_file, 4 * 1024 * 1024)?;
69 let file_md5 = calculate_md5(local_file)?;
70
71 println!("File size: {} bytes", file_size);
72 println!("File MD5: {}", file_md5);
73 println!("Block count: {}", block_list.len());
74 println!("Block list: {:?}", block_list);
75 println!();
76
77 let options = PrecreateOptions::new(remote_path, file_size, block_list)
78 .content_md5(&file_md5)
79 .rtype(1);
80
81 println!("Sending precreate request...");
82 match client.upload().precreate(options).await {
83 Ok(response) => {
84 println!("Precreate success!");
85 println!(" Upload ID: {}", response.uploadid);
86 println!(" Path: {:?}", response.path);
87 println!(" Return type: {}", response.return_type);
88 println!(" Block list to upload: {:?}", response.block_list);
89 }
90 Err(e) => {
91 println!("Precreate failed: {}", e);
92 }
93 }
94
95 Ok(())
96}Sourcepub fn content_md5(self, md5: &str) -> Self
pub fn content_md5(self, md5: &str) -> Self
Set content MD5 for the entire file
Examples found in repository?
examples/upload_precreate.rs (line 78)
43async fn main() -> Result<(), Box<dyn std::error::Error>> {
44 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
45
46 let client = BaiduNetDiskClient::builder().build()?;
47 info!("Client created successfully");
48
49 client.load_token_from_env()?;
50 info!("Token loaded successfully");
51
52 let args: Vec<String> = std::env::args().collect();
53
54 if args.len() < 3 {
55 println!("Usage: {} <local_file> <remote_path>", args[0]);
56 println!("Example: {} test.txt /apps/test/test.txt", args[0]);
57 return Ok(());
58 }
59
60 let local_file = &args[1];
61 let remote_path = &args[2];
62
63 println!("=== Baidu NetDisk Preupload Test ===");
64 println!("Local file: {}", local_file);
65 println!("Remote path: {}", remote_path);
66 println!();
67
68 let (file_size, block_list) = get_file_md5blocks(local_file, 4 * 1024 * 1024)?;
69 let file_md5 = calculate_md5(local_file)?;
70
71 println!("File size: {} bytes", file_size);
72 println!("File MD5: {}", file_md5);
73 println!("Block count: {}", block_list.len());
74 println!("Block list: {:?}", block_list);
75 println!();
76
77 let options = PrecreateOptions::new(remote_path, file_size, block_list)
78 .content_md5(&file_md5)
79 .rtype(1);
80
81 println!("Sending precreate request...");
82 match client.upload().precreate(options).await {
83 Ok(response) => {
84 println!("Precreate success!");
85 println!(" Upload ID: {}", response.uploadid);
86 println!(" Path: {:?}", response.path);
87 println!(" Return type: {}", response.return_type);
88 println!(" Block list to upload: {:?}", response.block_list);
89 }
90 Err(e) => {
91 println!("Precreate failed: {}", e);
92 }
93 }
94
95 Ok(())
96}Sourcepub fn local_ctime(self, ctime: u64) -> Self
pub fn local_ctime(self, ctime: u64) -> Self
Set local creation time (timestamp)
Sourcepub fn local_mtime(self, mtime: u64) -> Self
pub fn local_mtime(self, mtime: u64) -> Self
Set local modification time (timestamp)
Trait Implementations§
Source§impl Clone for PrecreateOptions
impl Clone for PrecreateOptions
Source§fn clone(&self) -> PrecreateOptions
fn clone(&self) -> PrecreateOptions
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PrecreateOptions
impl Debug for PrecreateOptions
Source§impl Default for PrecreateOptions
impl Default for PrecreateOptions
Source§fn default() -> PrecreateOptions
fn default() -> PrecreateOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for PrecreateOptions
impl RefUnwindSafe for PrecreateOptions
impl Send for PrecreateOptions
impl Sync for PrecreateOptions
impl Unpin for PrecreateOptions
impl UnsafeUnpin for PrecreateOptions
impl UnwindSafe for PrecreateOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more