Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Request body is rejected as too large in Next.js (1 MB default)

ErrorBody exceeded 1mb limit

Short answer

Next.js limits request bodies to 1 MB by default, in both Pages Router API routes and Server Actions. Raise the limit with the setting that matches the code that receives the request. On Vercel a separate fixed 4.5 MB cap applies, so larger files must go straight from the browser to storage.

  • Applies to Next.js 15, Next.js 16, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which kind of handler receives the request. The setting lives in a different place for each.

    ls pages/api app/api 2>/dev/null; grep -rln "use server" app lib 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The file is under pages/api and the request carries a large JSON or base64 bodyA Pages Router API route uses the default body parser limitFix
    2. 2A form with a file input posts to a function marked 'use server'A Server Action receives a body above its limitFix
    3. 3The response is 413 with FUNCTION_PAYLOAD_TOO_LARGE on Vercel, even after raising the Next.js limitThe request is above the 4.5 MB Vercel function limitFix

What does the error look like?

  • Body exceeded 1mb limit
  • 413 Payload Too Large
  • FUNCTION_PAYLOAD_TOO_LARGE

Cause 1 of 3

A Pages Router API route uses the default body parser limit

1Check

API routes parse the body for you and apply bodyParser.sizeLimit, which defaults to 1mb.

grep -rn "bodyParser" pages/api

2Fix

Export a config object from that route file and set a larger sizeLimit, using a size string the bytes package understands.

// pages/api/upload.js
export const config = {
  api: {
    bodyParser: {
      sizeLimit: '8mb',
    },
  },
}

3Verify

Send a body larger than 1 MB and confirm the route answers normally.

head -c 3000000 /dev/zero | curl -s -o /dev/null -w "%{http_code}\n" -X POST --data-binary @- -H "Content-Type: application/octet-stream" http://localhost:3000/api/upload

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

A Server Action receives a body above its limit

1Check

Server Actions also cap the request body at 1 MB by default. The limit counts the raw HTTP body, so multipart boundaries and field headers add roughly 10 to 20 KB on top of the file.

grep -n "serverActions" next.config.*

2Fix

Set serverActions.bodySizeLimit in next.config, leaving some room above the largest file you accept.

// next.config.js
module.exports = {
  experimental: {
    serverActions: {
      bodySizeLimit: '4mb',
    },
  },
}

3Verify

Restart the server, since next.config is read at startup, and submit the form again.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

The request is above the 4.5 MB Vercel function limit

1Check

Vercel rejects function request bodies above 4.5 MB before your code runs, so no Next.js setting can lift it. Compare your file size with that number.

ls -lh ./sample-upload.pdf

2Fix

Send large files from the browser straight to storage such as Vercel Blob, and let your route handle only a small token request or the resulting URL. Splitting the data into several requests also works.

// client component
import { upload } from '@vercel/blob/client'

const blob = await upload(file.name, file, {
  access: 'public',
  handleUploadUrl: '/api/blob/upload',
})

3Verify

Upload a file above 5 MB and confirm no 413 appears in the network tab.

# browser DevTools, Network tab: the upload request goes to the storage host, status 200

Confirmed by vercel.com

Did this fix it?

How do I stop it coming back?

  • Set the limit on purpose when you add a file field, and check it against the largest file you allow.
  • Validate file size in the browser before sending, so users see a clear message.
  • For files above a few MB, plan for direct-to-storage uploads from the start.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.