Async http PUT in loop with reqwest #4264
-
In Rust, using pub async fn put(input: &str, output: &str, _: &WrappedBar) {
let file = tokio::fs::File::open(input).await.unwrap();
let stream = tokio_util::codec::FramedRead::new(file, tokio_util::codec::BytesCodec::new());
let body = reqwest::Body::wrap_stream(stream);
let _ = reqwest::Client::new()
.put(output)
.header("content-type", "application/octet-stream")
.body(body)
.send()
.await
.unwrap();
loop {
let uploaded = file.seek(std::io::SeekFrom::Current(0)).await.unwrap();
// use the client.body(body).send().await.unwrap() here instead of outside the loop
// update the progress bar
if uploaded == file.metadata().await.unwrap().len() {
break;
}
}
}
reqwest = { version = "0.11.3", features = ["stream"] }
tokio = { version = "1.14.0", features = ["full"] }
tokio-util = "0.6.9"
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
This is not possible. You will need to set up some other way to transmit this data. For example, you can create your own body using the |
Beta Was this translation helpful? Give feedback.
This is not possible. You will need to set up some other way to transmit this data. For example, you can create your own body using the
async-stream
crate which behaves like your codec, except that it also transmits the number of bytes read to awatch
channel.