Skip to content

Commit

Permalink
fix: fix empty file upload failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
w1tcher authored and tu6ge committed Jul 8, 2024
1 parent 88fd5a5 commit c9c771c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
}

0 comments on commit c9c771c

Please sign in to comment.