Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(comfy): route I2V/I2I image upload through the Rust proxy (comfy_upload_image)

purple31183ba83869
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index b9aff1a3..8d7bfe62 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -3945,6 +3945,7 @@ dependencies = [
"js-sys",
"log",
"mime",
+ "mime_guess",
"native-tls",
"percent-encoding",
"pin-project-lite",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index af015c7f..3f43d9f5 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -16,7 +16,7 @@ tauri-plugin-single-instance = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
-reqwest = { version = "0.12", features = ["stream", "blocking", "json"] }
+reqwest = { version = "0.12", features = ["stream", "blocking", "json", "multipart"] }
zip = "2"
dirs = "6"
regex = "1"
diff --git a/src-tauri/src/commands/proxy.rs b/src-tauri/src/commands/proxy.rs
index 9e4b7ea4..6fcf8b1a 100644
--- a/src-tauri/src/commands/proxy.rs
+++ b/src-tauri/src/commands/proxy.rs
@@ -510,6 +510,47 @@ pub fn cancel_proxy_stream(
Ok(())
}
+/// Upload an image to ComfyUI's `/upload/image` as a clean multipart POST from
+/// Rust. `uploadImage()` in the frontend used a RAW browser `fetch()` — the only
+/// non-proxy fetch left — which 400'd on some WebView2 builds (multipart /
+/// boundary / CORS-preflight quirks; konata 2026-06-14 "Failed to upload image:
+/// HTTP 400"). reqwest's multipart is machine-independent and removes WebView2
+/// as a variable, matching the "everything via the Rust proxy" pattern
+/// (WebView2-149 finding). Returns ComfyUI's JSON body ({ name, subfolder, type }).
+#[tauri::command]
+pub async fn comfy_upload_image(
+ url: String,
+ filename: String,
+ content_type: Option<String>,
+ file_bytes: Vec<u8>,
+ state: tauri::State<'_, crate::state::AppState>,
+) -> Result<String, String> {
+ validate_proxy_url(&url, &state)?;
+ if file_bytes.is_empty() {
+ return Err("the source image is empty (0 bytes)".to_string());
+ }
+ let ct = content_type.filter(|c| !c.is_empty()).unwrap_or_else(|| "image/png".to_string());
+ let part = reqwest::multipart::Part::bytes(file_bytes)
+ .file_name(filename)
+ .mime_str(&ct)
+ .map_err(|e| e.to_string())?;
+ let form = reqwest::multipart::Form::new()
+ .part("image", part)
+ .text("overwrite", "true");
+ let client = reqwest::Client::builder()
+ .timeout(std::time::Duration::from_secs(120))
+ .build()
+ .map_err(|e| e.to_string())?;
+ let resp = client.post(&url).multipart(form).send().await
+ .map_err(|e| format!("comfy_upload_image: {}", e))?;
+ let status = resp.status();
+ let body = resp.text().await.unwrap_or_default();
+ if !status.is_success() {
+ return Err(format!("HTTP {}: {}", status.as_u16(), body.trim()));
+ }
+ Ok(body)
+}
+
/// Streaming Ollama model pull — emits per-model progress events.
/// Each event is a JSON object: { "model": "name", "data": { ...ollama progress... } }
#[tauri::command]
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 9471679f..b4746550 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -207,6 +207,7 @@ fn main() {
commands::proxy::proxy_localhost_stream,
commands::proxy::proxy_localhost_stream_chunked,
commands::proxy::cancel_proxy_stream,
+ commands::proxy::comfy_upload_image,
commands::proxy::register_openai_host,
commands::proxy::pull_model_stream,
commands::proxy::cancel_model_pull,
diff --git a/src/api/comfyui.ts b/src/api/comfyui.ts
index 6cf802fb..3935bc76 100644
--- a/src/api/comfyui.ts
+++ b/src/api/comfyui.ts
@@ -1,4 +1,4 @@
-import { comfyuiUrl, localFetch, fetchLocalhostBytes } from "./backend"
+import { comfyuiUrl, localFetch, fetchLocalhostBytes, isTauri, backendCall } from "./backend"
import { log } from "../lib/logger"
// ─── Control-plane fetch timeouts ───
@@ -967,6 +967,33 @@ export async function uploadImage(file: File): Promise<string> {
// sanitised filename with a real image extension rather than trusting file.name
// (a Blob-derived File can carry "" or an extension-less name).
const safeName = ensureImageFilename(file.name, file.type)
+
+ // Tauri (packaged): post the multipart from Rust. The raw browser fetch()
+ // below was the ONLY non-proxy fetch left in the app, and it 400'd on some
+ // WebView2 builds (multipart/boundary/CORS-preflight quirks; konata
+ // 2026-06-14 "Failed to upload image: HTTP 400"). reqwest's multipart is
+ // machine-independent and removes WebView2 as a variable — matching the
+ // "everything via the Rust proxy" pattern (WebView2-149 finding). Dev/browser
+ // keeps the direct fetch (Vite proxy / CORS-enabled ComfyUI).
+ if (isTauri()) {
+ const bytes = Array.from(new Uint8Array(await file.arrayBuffer()))
+ let body: string
+ try {
+ body = await backendCall<string>('comfy_upload_image', {
+ url: comfyuiUrl('/upload/image'),
+ filename: safeName,
+ contentType: file.type || 'image/png',
+ fileBytes: bytes,
+ })
+ } catch (e) {
+ // The Rust side rejects with "HTTP <s>: <body>" — surface ComfyUI's
+ // actual reason so the dropzone error is self-explanatory.
+ throw new Error(`Failed to upload image: ${e instanceof Error ? e.message : String(e)}`)
+ }
+ const data = JSON.parse(body)
+ return data.name // ComfyUI returns { name, subfolder, type }
+ }
+
const formData = new FormData()
formData.append('image', file, safeName)
formData.append('overwrite', 'true')