Reputation: 353
I would like to write a client that uploads a file to a server. I'm writing both the client and server in Rust, and I'd like the upload to stream so that the file does not need to load entirely into application-memory. My client, which looks like this...
use reqwest::{multipart, Body, Error, Response};
use tokio_util::codec::{BytesCodec, FramedRead};
#[tokio::main]
pub async fn upload_file(url : &str, path : &str) -> Result<Response, Error> {
let file = tokio::fs::File::open(path).await.unwrap();
let body = Body::wrap_stream(FramedRead::new(file, BytesCodec::new()));
let file_stream_part = multipart::Part::stream(body);
let form = multipart::Form::new().part("file", file_stream_part);
reqwest::Client::new().post(url).multipart(form).send().await
}
... elicits a 411 from my server, which looks like this:
#[tokio::main]
pub async fn serve(socket_address: SocketAddr) {
warp::serve(warp::path("upload")
.and(warp::post())
.and(warp::multipart::form())
.and_then(move |form| process_upload(form)))
.run(socket_address).await;
}
It seems like warp is rejecting the request for not having a length header before it even gets to process_upload.
What's the right way through this?
Upvotes: 0
Views: 37