Skip to content

fix: resolve 413 Request Entity Too Large in next-image template#722

Open
285729101 wants to merge 2 commits intoMerit-Systems:masterfrom
285729101:fix/next-image-size-limit
Open

fix: resolve 413 Request Entity Too Large in next-image template#722
285729101 wants to merge 2 commits intoMerit-Systems:masterfrom
285729101:fix/next-image-size-limit

Conversation

@285729101
Copy link

Fixes #561

The next-image template was hitting HTTP 413 because base64 data URLs easily blow past the default 1MB body parser limit. The export const config blocks in the route files were using Pages Router syntax which is silently ignored in App Router.

This PR takes a two-pronged approach:

Server side:

  • Set serverActions.bodySizeLimit to 4.5mb (Vercel max) in next.config.ts
  • Remove the broken Pages Router config exports from both route handlers and replace with maxDuration route segment config

Client side:

  • Added compressImageDataUrl() in image-utils.ts that resizes images to 1024px max dimension and converts to JPEG with iterative quality reduction (starts at 0.85, drops until under 3MB)
  • Wired it into image-generator.tsx so all attachment images get compressed before being sent as base64 to the API

This keeps things self-hostable (no blob store dependency) while staying well within Vercel's limits. The compression is pretty lightweight -- just canvas resize + JPEG encoding, no external libs needed.

- Add client-side image compression (resize to 1024px max, JPEG with
  iterative quality reduction) before sending base64 data URLs to API
- Increase Next.js body size limit to 4.5mb via serverActions config
- Remove broken Pages Router bodyParser config from App Router routes
  and replace with proper route segment config (maxDuration)
@vercel
Copy link
Contributor

vercel bot commented Feb 18, 2026

@285729101 is attempting to deploy a commit to the Merit Systems Team on Vercel.

A member of the Team first needs to authorize it.

@285729101
Copy link
Author

@rsproule this one fixes a real bug — the Pages Router export const config block was being silently ignored in App Router routes, causing 413 errors for large images. Happy to walk through the fix if helpful.

The serverActions.bodySizeLimit config only applies to Server Actions,
not Route Handlers. Since this template uses Route Handlers (route.ts),
the config had no effect. The client-side image compression already
handles body size reduction to prevent 413 errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

next-image template: Request Entity Too Large

1 participant