{"record":{"id":"3a1937d86ce1b46c","repo":"withastro/astro","slug":"content-too-large","errorCode":"CONTENT_TOO_LARGE","errorMessage":"Request body exceeds ${bodySizeLimit} bytes","messagePattern":"Request body exceeds (.+?) bytes","errorType":"error_code","errorClass":"ActionError","httpStatus":413,"severity":"error","filePath":"packages/astro/src/actions/runtime/server.ts","lineNumber":266,"sourceCode":"\tif (ctx.routePattern === ACTION_RPC_ROUTE_PATTERN) {\n\t\treturn { from: 'rpc', name: ctx.url.pathname.replace(/^.*\\/_actions\\//, '') } as const;\n\t}\n\tconst queryParam = ctx.url.searchParams.get(ACTION_QUERY_PARAMS.actionName);\n\tif (queryParam) {\n\t\treturn { from: 'form', name: queryParam } as const;\n\t}\n\treturn undefined;\n}\n\nasync function parseRequestBody(request: Request, bodySizeLimit: number) {\n\tconst contentType = request.headers.get('content-type');\n\tconst contentLengthHeader = request.headers.get('content-length');\n\tconst contentLength = contentLengthHeader ? Number.parseInt(contentLengthHeader, 10) : undefined;\n\tconst hasContentLength = typeof contentLength === 'number' && Number.isFinite(contentLength);\n\n\tif (!contentType) return undefined;\n\tif (hasContentLength && contentLength > bodySizeLimit) {\n\t\tthrow new ActionError({\n\t\t\tcode: 'CONTENT_TOO_LARGE',\n\t\t\tmessage: `Request body exceeds ${bodySizeLimit} bytes`,\n\t\t});\n\t}\n\ttry {\n\t\tif (hasContentType(contentType, formContentTypes)) {\n\t\t\tif (!hasContentLength) {\n\t\t\t\tconst body = await readBodyWithLimit(request.clone(), bodySizeLimit);\n\t\t\t\tconst formRequest = new Request(request.url, {\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\theaders: request.headers,\n\t\t\t\t\tbody: toArrayBuffer(body),\n\t\t\t\t});\n\t\t\t\treturn await formRequest.formData();\n\t\t\t}\n\t\t\treturn await request.clone().formData();\n\t\t}\n\t\tif (hasContentType(contentType, ['application/json'])) {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/actions/runtime/server.ts#L248-L284","documentation":"parseRequestBody reads the Content-Length header; if the declared body size is greater than the configured bodySizeLimit, the request is rejected before the body is read, with ActionError code CONTENT_TOO_LARGE (HTTP 413).","triggerScenarios":"An action request whose Content-Length exceeds the configured bodySizeLimit (the default cap applies when none is set).","commonSituations":"Uploading a large JSON payload or base64 file to a JSON action; increasing payload size without raising the limit; clients/proxies that report an accurate large Content-Length.","solutions":["Raise bodySizeLimit for the action/server config if larger payloads are legitimate.","Reduce the payload size (paginate, compress, or split the request).","Route large uploads through a dedicated file-upload endpoint or object storage instead of an action."],"exampleFix":"// before - default limit rejects a 2MB JSON body\n// astro.config / action config\nexport default defineConfig({\n  // ...\n});\n// after - raise the limit where the action/server is configured\n// (set bodySizeLimit to a value above your max payload, e.g. 3MB)","handlingStrategy":"validation","validationCode":"// Reject oversized payloads before sending, based on a known limit.\nconst MAX = 1024 * 1024; // mirror the configured bodySizeLimit\nconst size = new Blob([JSON.stringify(payload)]).size;\nif (size > MAX) throw new Error(`Payload ${size}B exceeds the ${MAX}B limit`);","typeGuard":null,"tryCatchPattern":"try {\n  await actions.upload(payload);\n} catch (e) {\n  if (e instanceof ActionError && e.code === 'CONTENT_TOO_LARGE') {\n    // ask user to reduce size, or route to a file endpoint\n  } else throw e;\n}","preventionTips":["Set bodySizeLimit deliberately to your real maximum payload.","Compress or paginate large JSON payloads.","Send large files to a dedicated upload endpoint, not an action."],"tags":["actions","payload-limit","http-413","config"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}