From 7b70865a81154271a56d057fefab25f956c617bd Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Fri, 17 Apr 2026 13:16:29 -0400 Subject: [PATCH] fix(rsplat): inline resized image as data URI for Hunyuan3D fal.ai was returning "invalid images found in the input, failed to read/process" because it couldn't reliably fetch the staged image URL through Cloudflare/Traefik. Encode the resized JPEG inline so the fetch stays inside the fal.ai request and doesn't depend on our origin being reachable from their crawler. Co-Authored-By: Claude Opus 4.7 (1M context) --- server/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/index.ts b/server/index.ts index a49e1598..e5306945 100644 --- a/server/index.ts +++ b/server/index.ts @@ -1426,7 +1426,9 @@ async function process3DGenJob(job: Gen3DJob) { const MODEL = "fal-ai/hunyuan3d-v21"; try { - // 1. Resize staged image with sharp (max 1024px) for reliable fal.ai processing + // 1. Resize staged image with sharp (max 1024px) and inline as data URI so fal.ai + // never has to fetch from our origin (Cloudflare/Traefik/subdomain routing can + // intermittently block fal.ai's fetcher → "invalid images found in the input"). let imageInput = job.imageUrl; const stagedMatch = job.imageUrl.match(/\/(?:api\/files|data\/files)\/generated\/([^?#]+)/); if (stagedMatch) { @@ -1439,11 +1441,8 @@ async function process3DGenJob(job: Gen3DJob) { .resize(1024, 1024, { fit: "inside", withoutEnlargement: true }) .jpeg({ quality: 90 }) .toBuffer(); - const resizedName = `stage-resized-${Date.now()}-${Math.random().toString(36).slice(2, 6)}.jpg`; - await Bun.write(resolve(dir, resizedName), resizedBuf); - // Use public HTTPS URL for the resized image - imageInput = `${PUBLIC_ORIGIN}/api/files/generated/${resizedName}`; - console.log(`[3d-gen] Resized image: ${Math.round(resizedBuf.length / 1024)}KB → ${imageInput}`); + imageInput = `data:image/jpeg;base64,${resizedBuf.toString("base64")}`; + console.log(`[3d-gen] Inlined resized image: ${Math.round(resizedBuf.length / 1024)}KB (data URI)`); } } catch (e: any) { console.warn(`[3d-gen] Resize failed, using original URL:`, e.message);