From e79ee0e20e25e39dd29627dcaa1f898c1fdb247c Mon Sep 17 00:00:00 2001 From: iz0eyj Date: Wed, 25 Nov 2026 17:22:45 +0100 Subject: [PATCH] fix(uploads): raise body limit so images/PDFs/exes upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The /api/uploads route used axum's standard Json extractor, whose default 2 MiB body limit silently 413-rejected any base64 payload over ~2 MiB — small .txt files worked but images, PDFs and executables never reached the handler. Apply DefaultBodyLimit::max(64 MiB) to the upload route (a 32 MiB decoded file is ~43 MiB of base64), so the handler runs and applies its own decoded-size cap. Regression test: a ~3 MiB binary upload now returns 200 (kind=binary). Verified live with a 3.0 MiB PNG, 3.1 MiB PDF and 3.1 MiB exe: all upload, classify correctly, and binaries are handed to the model as path reminders. --- README.md | 2 +- src/api/routes.rs | 9 ++++++++- tests/api_sessions.rs | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7e1406e..2dc6ece 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ later adaptation round. ## Status -Working and tested (122 tests, plus 2 real-file tests run on demand). Text, images, +Working and tested (123 tests, plus 2 real-file tests run on demand). Text, images, the full client-side tool loop, the Anthropic endpoint, the web GUI (session context, streaming, stats, **file/image upload**) and **agent mode** (the model using `shell_exec` on the host) have been validated live against the real Inkling diff --git a/src/api/routes.rs b/src/api/routes.rs index 63a3127..aace55c 100644 --- a/src/api/routes.rs +++ b/src/api/routes.rs @@ -80,7 +80,14 @@ fn build_router(state: AppState, auth: AuthConfig) -> Router { ) .route("/api/sessions/{id}/messages", get(sessions::get_messages)) .route("/api/sessions/{id}/chat", post(sessions::session_chat)) - .route("/api/uploads", post(uploads::upload)) + .route( + "/api/uploads", + // Uploads arrive as base64 JSON: a 32 MiB decoded file becomes + // ~43 MiB on the wire, well over axum's 2 MiB default body limit + // (which silently 413-rejected images/PDFs/exes). Allow 64 MiB so + // the handler runs and applies its own decoded-size cap. + post(uploads::upload).layer(axum::extract::DefaultBodyLimit::max(64 * 1024 * 1024)), + ) .route( "/api/settings/defaults", get(sessions::get_defaults).put(sessions::put_defaults), diff --git a/tests/api_sessions.rs b/tests/api_sessions.rs index 957a670..3a662d1 100644 --- a/tests/api_sessions.rs +++ b/tests/api_sessions.rs @@ -519,3 +519,24 @@ async fn upload_routes_by_kind_and_attaches_to_chat() { let _ = std::fs::remove_file(&path); } + +#[tokio::test] +async fn upload_accepts_large_binary_over_default_body_limit() { + use base64::Engine; + let (app, _store) = build_app().await; + // ~3 MiB of binary -> ~4 MiB of base64, above axum's 2 MiB default body limit + // (which used to 413-reject images/PDFs/exes before reaching the handler). + let bytes = vec![0u8; 3 * 1024 * 1024]; + let data = base64::engine::general_purpose::STANDARD.encode(&bytes); + let (st, text) = req( + &app, + Method::POST, + "/api/uploads", + Some(serde_json::json!({"name": "big.bin", "data": data})), + ) + .await; + assert_eq!(st, StatusCode::OK, "{text}"); + let meta: serde_json::Value = serde_json::from_str(&text).unwrap(); + assert_eq!(meta["kind"], "binary"); + let _ = std::fs::remove_file(meta["path"].as_str().unwrap()); +}