fix: compress images in the browser so uploads clear the 1 MB ingress cap #4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claw/upload-compress-b7c2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #3.
Uploads over 1 MB failed with a bare
413. The cause is the platform ingress, which refuses bodies above 1 MB before Next.js is reached — so the 10 MB / 15 MB limits the app advertised could never be honoured, and no handler ran that could explain the failure.Approach
Re-encode photos in the browser, the only point where the limit can be met without a platform change. New
src/lib/media/compress.ts: downscale to a 2560px longest edge, re-encode to WebP (JPEG fallback), stepping quality down and then dimensions until the result fits a 900 KB budget — under the cap with headroom for multipart overhead.Files already under budget and within the dimension limit pass through untouched, so nothing is needlessly degraded.
Validation split by what it judges:
validateSourceFileon what was picked,validateMediaFileon what is actually sent.Verified against a real browser
Driven through the admin UI with Playwright on a local dev server:
The video case now reads: "Video is 2.9 MB — video files cannot be compressed in the browser and the upload limit is 0.9 MB. Compress it before uploading, or host it externally and link to it."
npm run type-checkandnpm run buildboth clean.Known limitation
Video and animated GIF can't be re-encoded in a canvas, so they're still bound by the 1 MB ingress cap — they now fail fast with an explanation rather than a raw 413. The real fix for those is
nginx.ingress.kubernetes.io/proxy-body-sizeon the ingress; no catalog-info field exposes it today.🤖 Generated with Claude Code