2026-05-052 min read

Image uploads, smoothed out

Why some phone photos used to fail with a cryptic error — and the three changes we shipped to fix it.

Share

If you tried a photo-input Look (Chibi Mini Me, Photo Vocabulary Scrapbook) over the past few days with a fresh phone shot, you might have seen something like this:

Unexpected token 'R', "Request En"... is not valid JSON

That isn't a server error. That's our frontend tripping over a server response we didn't expect to ever read. This week we fixed three things that were combining to create the mess.

Why it happened

Vercel — where FluxGen runs — caps serverless request bodies at 4.5 MB. We were:

So a 5 MB raw photo became a ~6.7 MB request body, and Vercel's edge sent back plain-text Request Entity Too Large with status 413 — before our route ever got to run. Meanwhile the frontend was calling res.json() blindly on every response. JSON.parse on the string Request En... throws Unexpected token 'R'. That stack trace is what landed on screen.

What we shipped

Three changes, defense-in-depth.

1. Auto-downscale on upload. Every image you drop now goes through a <canvas> before it leaves your browser — resized to a max of 1600 px on the longest side, JPEG quality 0.85. That's visually indistinguishable from the source for photo content, but it cuts the bytes by 60-70 %. The raw-file sanity cap went from 5 MB to 25 MB, so even heavy phone photos get through. The upload caption now reads auto-resized for upload instead of a hard size limit, because we handle it.

2. Inline error UI. Native alert() is gone. If something fails on the client side (wrong file type, decode error, oversized file), you see a small vermillion-bordered banner under the upload button — same styling as the rest of FluxGen, no jarring system dialog.

3. Friendly errors when the server rejects something. A new helper, parseErrorResponse, tries the server's JSON first; if the body isn't valid JSON (Vercel edge plain text, gateway HTML, anything else), it falls back to plain-English status-code messages:

You should never see a JSON parse stack as an error message again.

Net effect

Drop any phone photo, including a 15 MB one straight off an iPhone, and it just works. If something does fail, the error tells you what it is in plain English. Less friction, less confusion, fewer support tickets — exactly the kind of small fix we'd rather just ship than write about. (And then, sometimes, write about anyway.)