Axum S3 file downloading

⚓ Rust    📅 2026-06-24    👤 surdeus    👁️ 2      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Axum S3 file downloading

There are bunch of different crates that provides S3 interaction, like aws_sdk_s3, s3, minio

Result I wanted is to download large file from S3 by axum endpoint, for example "/file".

The core problem I met right now: when I try to download a file, rust service started to load data to RAM. I suppose it's not right behaviour..?

// Axum + rust-s3
pub async fn download_file_handler(Path(user): Path<Uuid>) -> impl IntoResponse {
    match download_file(user).await {
        Ok(stream) => {
            let response = axum::response::Response::builder();
            let body = axum::body::Body::from_stream(stream.bytes);
            response.body(body).unwrap()
        }
        Err(err) => "File download failure".into_response(),
    }
}

pub async fn download_file(user: Uuid) -> Result<ResponseDataStream> {
        let region = s3::Region::Custom {
            region: "".to_owned(),
            endpoint: S3_ENDPOINT.to_owned(),
        };
        let creds = s3::creds::Credentials::new(
            Some(S3_ACCESS_KEY),
            Some(S3_SECRET_KEY),
            None,
            None,
            None,
        )?;

        let bucket = s3::Bucket::new(CUSTOM_BUCKET, region, creds)?.with_path_style();
        let stream = bucket
            .get_object_stream(format!("{}/{}", user, CUSTOM_FILE_NAME))
            .await?;
        Ok(stream)
    }

So, maybe someone have any ideas?

(I tried axum::response::Redirection, it works when I'm translating data directly from s3 with presigned request but it's interesting why previous way doesn't work)

8 posts - 3 participants

Read full topic

🏷️ Rust_feed