diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ecef3eb..7337fe3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -25,11 +25,12 @@ fuzzy-matcher = "0.3.7" jm_client_core = { path = "../jm_client_core" } log = "0.4.11" opener = "0.4.1" -reqwest = { version = "0.10", features = ["stream"] } +reqwest = { version = "0.11", features = ["stream", "multipart"] } serde_json = "1.0.60" structopt = "0.3.21" term-table = "1.3.0" term_size = "0.3.2" -tokio = { version = "0.2.23", features = ["macros", "fs", "process"] } +tokio = { version = "1.7.0", features = ["macros", "fs", "process", "rt-multi-thread"] } +tokio-util = { version = "0.6.7", features = ["codec"] } url = "2.2.0" diff --git a/cli/src/commands/up.rs b/cli/src/commands/up.rs index edcb71b..85443c0 100644 --- a/cli/src/commands/up.rs +++ b/cli/src/commands/up.rs @@ -1,12 +1,11 @@ use crate::util; -use anyhow::{Result, bail}; +use anyhow::{bail, Result}; use jm_client_core::{api::UpResp, JMClient}; use log::info; -use reqwest::{ - multipart::{Form, Part}, - Body, -}; -use tokio::{fs::File, io::reader_stream}; +use reqwest::multipart::{Form, Part}; +use reqwest::Body; +use tokio::fs::File; +use tokio_util::codec::{BytesCodec, FramedRead}; pub async fn run( client: &JMClient, @@ -27,10 +26,13 @@ pub async fn run( .text("token", token) .part( "file", - Part::stream(Body::wrap_stream(reader_stream({ - info!("Opening file {}", &path); - File::open(path).await? - }))) + Part::stream(Body::wrap_stream(FramedRead::new( + { + info!("Opening file {}", &path); + File::open(path).await? + }, + BytesCodec::new(), + ))) .file_name(name), ), ) @@ -43,15 +45,12 @@ pub async fn run( let res = if let Ok(res) = serde_json::from_slice::(bytes) { res + } else if let Ok(s) = std::str::from_utf8(bytes) { + bail!("Server responded with unexpected response: {}", s); } else { - if let Ok(s) = std::str::from_utf8(bytes) { - bail!("Server responded with unexpected response: {}", s); - } else { - bail!("Server responded with invalid utf8 bytes: {:?}", bytes); - } + bail!("Server responded with invalid utf8 bytes: {:?}", bytes); }; - println!("Server responded with code {}", status); if !open { diff --git a/jm_client_core/Cargo.toml b/jm_client_core/Cargo.toml index de5e20b..c06f9fa 100644 --- a/jm_client_core/Cargo.toml +++ b/jm_client_core/Cargo.toml @@ -12,9 +12,9 @@ env_logger = "0.8.2" lazy_static = "1.4.0" log = "0.4.11" once_cell = "1.5.2" -reqwest = "0.10.9" +reqwest = "0.11.3" serde = { version = "1.0.117", features = ["derive"] } serde_json = "1.0.60" thiserror = "1.0.23" -tokio = { version = "0.2.23", features = ["macros", "fs"] } +tokio = { version = "1.7.0", features = ["macros", "fs", "rt-multi-thread"] } url = "2.2.0"