{"record":{"id":"b04f5f5606fbd9ee","repo":"payloadcms/payload","slug":"error-message","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/payload/src/utilities/addDataAndFileToRequest.ts","lineNumber":45,"sourceCode":"        req.json = () => Promise.resolve(data)\n      } catch (error) {\n        if (error instanceof SyntaxError) {\n          throw new APIError('Invalid JSON', 400)\n        }\n        req.payload.logger.error(error)\n        throw error\n      }\n    } else if ((bodyByteSize || hasBodyStream) && contentType?.includes('multipart/')) {\n      const { error, fields, files } = await processMultipartFormdata({\n        options: {\n          ...(payload.config.bodyParser || {}),\n          ...(payload.config.upload || {}),\n        },\n        request: req as Request,\n      })\n\n      if (error) {\n        throw new APIError(error.message)\n      }\n\n      // Set all files on req.files for access by hooks\n      if (files) {\n        req.files = files\n        // Backwards compatibility: set req.file for standard upload collections\n        // Guard: if multiple files share the field name \"file\", files.file is an array — skip\n        if (files.file && !Array.isArray(files.file)) {\n          req.file = files.file\n        }\n      }\n\n      if (fields?._payload && typeof fields._payload === 'string') {\n        req.data = JSON.parse(fields._payload)\n      }\n\n      if (!req.file && fields?.file && typeof fields?.file === 'string') {\n        let uploadedFile: UploadInstructions['file']","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/utilities/addDataAndFileToRequest.ts#L27-L63","documentation":"Thrown when the multipart/form-data parser (`processMultipartFormdata`) returns an `error` object while processing the incoming request body. The thrown `APIError` carries the parser own message, so the exact text varies (hence the placeholder `error.message`).","triggerScenarios":"A POST/PATCH/PUT with a `multipart/` content type where the body is malformed: missing `Content-Length` with a streaming body, malformed boundary, fields exceeding the configured `bodyParser` size limits, or upload limits (`maxFileSize`, `maxFields`) being exceeded.","commonSituations":"File size exceeds `upload.maxFileSize` or the multipart parser limit; number of form fields exceeds `bodyParser.fields` / `maxFields`; the multipart boundary is missing or duplicated; a streaming request with no `Content-Length` hits a buffer limit; client uses an outdated multipart encoding.","solutions":["Read the exact `error.message` from the API response to identify the specific limit hit (size, field count, parse error).","Increase the relevant limit in `config.upload` or `config.bodyParser` if the upload is legitimately large.","Reduce the file size or number of fields on the client side if the limit is intentional.","Ensure the client sends a well-formed multipart body with a correct `boundary` parameter in `Content-Type`."],"exampleFix":"// before -- default limits too small for intended uploads\nupload: { limits: { fileSize: 1000000 } } // 1 MB\n\n// after\nupload: { limits: { fileSize: 50000000 } } // 50 MB\nbodyParser: { sizeLimit: 52428800 }","handlingStrategy":"validation","validationCode":"// Before sending, check file sizes against configured limits\nconst maxFileSize = payloadConfig.upload?.limits?.fileSize ?? Infinity\nfor (const f of files) {\n  if (f.size > maxFileSize) {\n    throw new Error(`File ${f.name} exceeds maxFileSize (${maxFileSize} bytes)`)\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fetch(url, { method: 'POST', body: formData })\n} catch (e) {\n  if (e instanceof APIError) {\n    // e.message contains the specific parser error -- address size/field/parse issue\n  } else throw e\n}","preventionTips":["Set upload.limits.fileSize and bodyParser.sizeLimit to values your app expects.","Validate file sizes client-side before upload to fail fast.","Use well-formed multipart bodies with correct boundary parameters.","Monitor the exact error.message to distinguish size vs parse errors."],"tags":["multipart","upload","body-parsing","limits"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}