I have a multipart form endpoint in my Axum app. File upload form field is supposed to be read like this:
// let mut field: axum::extract::multipart::Field
while let Some(chunk) = field.chunk().await? {
// Do something with chunk: Bytes
}
// Done
On other side I have s3::Bucket (rust-s3 crate) and its method put_object_stream expects tokio::io::AsyncRead. How to make them work together without saving the whole file in the memory or on the disk?
If you have a multipart
Fieldand want to use it as atokio::io::AsyncReadtype, you can usetokio_util::io::StreamReadersinceFieldimplementsStream<Item = Result<Bytes, MultipartError>>. Though becauseAsyncRead's interface usesstd::io::Erroryou'll have to convertMultipartErrorto it first.