{"record":{"id":"90a63739e4394a28","repo":"vercel/next.js","slug":"body-exceeded-bodysizelimit-limit-to-configure","errorCode":null,"errorMessage":"Body exceeded ${bodySizeLimit} limit.\nTo configure the body size limit for Server Actions, see: https://nextjs.org/docs/app/api-reference/next-config-js/serverActions#bodysizelimit","messagePattern":"Body exceeded (.+?) limit\\.\nTo configure the body size limit for Server Actions, see: https://nextjs\\.org/docs/app/api-reference/next-config-js/serverActions#bodysizelimit","errorType":"http","errorClass":"ApiError","httpStatus":413,"severity":"error","filePath":"packages/next/src/server/app-render/action-handler.ts","lineNumber":821,"sourceCode":"\n          temporaryReferences = createTemporaryReferenceSet()\n\n          if (isMultipartAction) {\n            // TODO-APP: Add streaming support\n            // Read the body stream with size tracking to enforce bodySizeLimitBytes.\n            // We cannot call req.request.formData() directly as that would bypass\n            // the body size limit entirely.\n            const edgeChunks: Uint8Array[] = []\n            let edgeBodySize = 0\n            const edgeReader = req.body.getReader()\n            while (true) {\n              const { done, value } = await edgeReader.read()\n              if (done) break\n              edgeBodySize += value.byteLength\n              if (edgeBodySize > bodySizeLimitBytes) {\n                const { ApiError } =\n                  require('../api-utils') as typeof import('../api-utils')\n                throw new ApiError(\n                  413,\n                  `Body exceeded ${bodySizeLimit} limit.\\n` +\n                    `To configure the body size limit for Server Actions, see: https://nextjs.org/docs/app/api-reference/next-config-js/serverActions#bodysizelimit`\n                )\n              }\n              edgeChunks.push(value)\n            }\n            // Reconstruct a Blob from the buffered chunks and parse formData from it.\n            // Note: we must pass the original Content-Type as an explicit header\n            // rather than relying on the Blob's `type`. The Blob constructor\n            // normalizes `type` to ASCII lowercase per the File API spec, which\n            // would lowercase the multipart boundary parameter (e.g.\n            // `boundary=----WebKitFormBoundaryAbCdEf`). The body bytes contain the\n            // original mixed-case boundary delimiter, so a lowercased boundary\n            // would fail to match and `formData()` would throw. An explicit header\n            // on the Request takes precedence over the Blob's normalized type.\n            const edgeBodyBlob = new Blob(edgeChunks as BlobPart[])\n            const formData = await new Request('http://n/', {","sourceCodeStart":803,"sourceCodeEnd":839,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/app-render/action-handler.ts#L803-L839","documentation":"A 413 ApiError thrown while streaming a multipart Server Action body on the edge runtime. The handler manually reads req.body chunks and accumulates byte length; once edgeBodySize exceeds bodySizeLimitBytes, this error aborts the read. bodySizeLimit comes from next.config.js serverActions.bodySizeLimit (default 1 MB).","triggerScenarios":"An edge-runtime Server Action receives a multipart/form-data POST (e.g. a form with a file upload or large fields). During the chunked read loop (lines 814-828), the cumulative edgeBodySize surpasses the configured limit and the ApiError is thrown.","commonSituations":"File uploads via Server Actions exceeding the default 1 MB; forms with many or large fields; users pasting large text. The limit is a safety/DoS guard, so legitimate large uploads need a config bump.","solutions":["Raise the limit in next.config.js: experimental.serverActions.bodySizeLimit (e.g. '5mb') to accommodate the upload size.","If the upload is genuinely large, prefer direct-to-storage uploads (e.g. presigned S3 URLs) rather than routing the file through a Server Action.","Validate file size on the client before submitting to give the user early feedback.","Confirm the limit string format is correct (e.g. '2mb', '500kb') so it parses to the intended bytes."],"exampleFix":"// next.config.js -- before\n// module.exports = { /* no serverActions config */ }\n\n// after\n// module.exports = {\n//   experimental: { serverActions: { bodySizeLimit: '5mb' } } \n// }","handlingStrategy":"validation","validationCode":"// Client-side size guard before submitting a multipart Server Action.\nconst MAX = 1 * 1024 * 1024 // match serverActions.bodySizeLimit\nfunction totalSize(formData: FormData): number {\n  let n = 0\n  formData.forEach((v) => { n += typeof v === 'string' ? v.length : (v as File).size })\n  return n\n}\nif (totalSize(fd) > MAX) { alert('Too large'); return }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set experimental.serverActions.bodySizeLimit to match your largest legitimate upload.","Prefer direct-to-storage uploads for large files.","Show client-side size warnings before submit.","Document the limit so contributors don't hit it unknowingly."],"tags":["server-actions","body-size-limit","edge-runtime","file-upload"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}