support s3:// syntax

This commit is contained in:
Diego Imbert
2025-08-06 13:27:20 +02:00
parent d4937ca0ec
commit 820fb4c0d2
2 changed files with 20 additions and 4 deletions
@@ -134,3 +134,13 @@ pub async fn download_s3_file_internal(
"Not implemented in Windmill's Open Source repository".to_string(),
))
}
#[cfg(not(feature = "private"))]
pub async fn read_object_streamable(
s3_client: Arc<dyn ObjectStore>,
file_key: &str,
) -> anyhow::Result<Response> {
Err(error::Error::internal_err(
"Not implemented in Windmill's Open Source repository".to_string(),
))
}
+10 -4
View File
@@ -17,17 +17,23 @@ use crate::{
};
pub fn workspaced_unauthed_service() -> Router {
Router::new().route("/:storage/:key", get(get_object))
Router::new().route("/*key", get(get_object))
}
async fn get_object(
Extension(db): Extension<DB>,
Path((w_id, storage, file_key)): Path<(String, String, String)>,
Path((w_id, full_key)): Path<(String, String)>,
) -> Result<Response> {
let full_key = full_key.strip_prefix("s3://").unwrap_or(&full_key);
let Some((storage, object_key)) = full_key.split_once('/').map(|(s, k)| (s, k)) else {
return Err(Error::InternalErr(
"Invalid S3 key : no storage".to_string(),
));
};
let storage = if storage.is_empty() {
None
} else {
Some(storage)
Some(storage.to_string())
};
// temp values
@@ -46,7 +52,7 @@ async fn get_object(
"No files storage resource defined at the workspace level".to_string(),
))?;
let s3_client = build_object_store_client(&s3_resource).await?;
let result = read_object_streamable(s3_client, &file_key).await?;
let result = read_object_streamable(s3_client, object_key).await?;
let stream = result.into_stream();
let stream_body = axum::body::Body::from_stream(stream);
Ok(stream_body.into_response())