From c9c771ccc3422aecbfb8283309b4f83bf1985008 Mon Sep 17 00:00:00 2001 From: w1tcher Date: Sun, 7 Jul 2024 22:22:14 +0800 Subject: [PATCH] fix: fix empty file upload failed. --- src/object.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/object.rs b/src/object.rs index bd4a93c..10913f6 100644 --- a/src/object.rs +++ b/src/object.rs @@ -181,7 +181,10 @@ impl Object { let method = Method::PUT; let resource = CanonicalizedResource::new(format!("/{}/{}", bucket.as_str(), self.path)); - let header_map = client.authorization(method, resource)?; + let mut header_map = client.authorization(method, resource)?; + if content.len() == 0 { + header_map.insert("Content-Length", 0.into()); + } let response = reqwest::Client::new() .put(url) @@ -335,4 +338,12 @@ mod tests { println!("{:?}", second_list); } + + #[tokio::test] + async fn test_upload_empty_file() { + let object = Object::new("empty.txt"); + + let info = object.upload(vec![], &set_client()).await; + assert!(info.is_ok()) + } }