upload/
upload.rs

1use std::path::PathBuf;
2
3use ffsend_api::{
4    action::upload::Error, action::upload::Upload, api::Version, client::ClientConfigBuilder,
5    file::remote_file::RemoteFile,
6};
7use url::Url;
8
9fn main() {
10    // Upload the given file, get and report it's share URL
11    let url = upload_file(PathBuf::from("./README.md"))
12        .expect("failed to upload file")
13        .download_url(true);
14    println!("Share URL: {}", url);
15}
16
17/// Upload the file at the given path. Returns uploaded file on success.
18fn upload_file(path: PathBuf) -> Result<RemoteFile, Error> {
19    // Build the client for uploading
20    let client_config = ClientConfigBuilder::default().build().unwrap();
21    let client = client_config.client(true);
22
23    #[cfg(feature = "send3")]
24    let version = Version::V3;
25    #[cfg(not(feature = "send3"))]
26    let version = Version::V2;
27
28    // Build upload action, and invoke to upload
29    let upload = Upload::new(
30        version,
31        Url::parse("https://send.firefox.com/").unwrap(),
32        path,
33        None,
34        None,
35        None,
36    );
37    Upload::invoke(upload, &client, None)
38}