Hi i want to send a tar archive with a docker image to docker build api. this is an example of how i am triyng to post that
// build image
pub fn build_image_fn(docker_api_ip: &str, image_name: &str, img_file_path: &str) -> Result<String, Error> {
let client = Client::new();
// read the tar
let file = File::open(img_file_path).unwrap();
println!("path: {img_file_path}");
// post
let url = format!("http://{docker_api_ip}/build?t={image_name}");
let response = client
.post(url)
.header("Content-Type", "application/tar")
.body(file)
.send();
// Check if the request was successful
match response {
Ok(response) => {
if response.status().is_success() {
Ok("Image builded successfully".to_string())
} else {
let status = response.status().clone();
let body = response.text().unwrap();
let err = serde_json::from_str::<ApiErr>(&body).expect("failed to deserialize build_image_fn error json");
let err_str = format!("Error: code:{}, message: {}", status, err.message);
Ok(err_str)
}
}
Err(err) => {
Err(err)
}
}
}
if i do that with curl using --data-binary to send my tar, the image builds successfuly so i would like to see if there is something to replicate the behaviour of --data-binary but in rust reqwest