I’m using axum rust to implement api that receive a file and put it into minio, the concept is all about stream, no get actual bytes array. I’m using https://crates.io/crates/minio
In my handler i have:
pub async fn process(
info: ClientRequest,
mut data: Multipart,
) -> Result<NoDataReponse, NoDataReponse> {
let bucket = check_res!(cc::get_s3_dataleak_bucket(), info);
let field = data.next_field().await.unwrap().unwrap();
let file_name = field.file_name().unwrap().to_string();
let fixed_error_body = field.map_err(|err| io::Error::new(io::ErrorKind::Other, err));
let buffer_reader = StreamReader::new(fixed_error_body);
let mut sync_reader = SyncIoBridge::new(buffer_reader);
s3::upload_data_stream(bucket, &file_name, &mut sync_reader)
.await
.unwrap();
Ok(NoDataReponse::ok())
}
minio upload function
pub async fn upload_data_stream<T>(bucket_name: &str, object_name: &str, data: &mut T) -> Result<()>
where
T: Read + Send,
{
let client = &CLIENT;
client
.put_object(&mut PutObjectArgs::new(
bucket_name,
object_name,
data,
None,
None,
)?)
.await?;
Ok(())
}
Why this error happened, i don’t know the root cause and the solution