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
Field
and want to use it as atokio::io::AsyncRead
type, you can usetokio_util::io::StreamReader
sinceField
implementsStream<Item = Result<Bytes, MultipartError>>
. Though becauseAsyncRead
's interface usesstd::io::Error
you'll have to convertMultipartError
to it first.