{"record":{"id":"3faac4eafcf38072","repo":"remix-run/remix","slug":"request-is-not-a-multipart-request-3faac4","errorCode":null,"errorMessage":"Request is not a multipart request","messagePattern":"Request is not a multipart request","errorType":"validation","errorClass":"MultipartParseError","httpStatus":null,"severity":"error","filePath":"packages/multipart-parser/src/lib/multipart.node.ts","lineNumber":74,"sourceCode":"  let contentType = req.headers['content-type']\n  return contentType != null && /^multipart\\//i.test(contentType)\n}\n\n/**\n * Parse a multipart Node.js request and yield each part as a {@link MultipartPart} object.\n *\n * @param req The Node.js `http.IncomingMessage` object containing multipart data\n * @param options Options for the parser, such as `maxHeaderSize`, `maxFileSize`, `maxParts`,\n * and `maxTotalSize`\n * @yields Parsed {@link MultipartPart} objects from the multipart request body\n * @returns An async generator yielding {@link MultipartPart} objects\n */\nexport async function* parseMultipartRequest(\n  req: http.IncomingMessage,\n  options?: MultipartParserOptions,\n): AsyncGenerator<MultipartPart, void, unknown> {\n  if (!isMultipartRequest(req)) {\n    throw new MultipartParseError('Request is not a multipart request')\n  }\n\n  let boundary = getMultipartBoundary(req.headers['content-type']!)\n  if (!boundary) {\n    throw new MultipartParseError('Invalid Content-Type header: missing boundary')\n  }\n\n  yield* parseMultipartStream(req, {\n    boundary,\n    maxHeaderSize: options?.maxHeaderSize,\n    maxFileSize: options?.maxFileSize,\n    maxParts: options?.maxParts,\n    maxTotalSize: options?.maxTotalSize,\n  })\n}\n","sourceCodeStart":56,"sourceCodeEnd":90,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/multipart-parser/src/lib/multipart.node.ts#L56-L90","documentation":"The Node-specific parseMultipartRequest(req) variant throws MultipartParseError when the http.IncomingMessage is not a multipart request, i.e. its content-type header is not multipart/form-data or multipart/mixed. It mirrors the web Request variant but reads req.headers['content-type'] from a raw Node server request.","triggerScenarios":"Calling the Node parseMultipartRequest with a req whose method has no multipart body (GET), whose content-type is application/json or urlencoded, or whose header casing/content differs from what isMultipartRequest expects.","commonSituations":"Express/Node http servers routing all POSTs into multipart parsing even when clients submit JSON or urlencoded forms; HTML forms missing enctype=\"multipart/form-data\"; health-check or prefetch requests hitting the upload endpoint.","solutions":["Check isMultipartRequest(req) before parsing and route non-multipart requests to a different handler","Ensure client forms use enctype=\"multipart/form-data\" or clients send FormData","Verify the content-type header survives any Node middleware (e.g. body-parser running first)"],"exampleFix":"// before\nfor await (let part of parseMultipartRequest(req)) { ... }\n\n// after\nimport { isMultipartRequest } from 'multipart-parser'\nif (!isMultipartRequest(req)) {\n  res.writeHead(415).end('Expected multipart request')\n  return\n}\nfor await (let part of parseMultipartRequest(req)) { ... }","handlingStrategy":"validation","validationCode":"import { isMultipartRequest } from 'multipart-parser'\n\nif (!isMultipartRequest(req)) {\n  res.writeHead(415, { 'Content-Type': 'text/plain' })\n  return res.end('Expected multipart/form-data')\n}","typeGuard":"import { isMultipartRequest } from 'multipart-parser'\n\nconst isMultipart = (req: http.IncomingMessage): boolean => isMultipartRequest(req)","tryCatchPattern":"try {\n  for await (let part of parseMultipartRequest(req)) { /* ... */ }\n} catch (error) {\n  if (error instanceof MultipartParseError && error.message.includes('not a multipart')) {\n    res.writeHead(415).end('Expected multipart request')\n    return\n  }\n  throw error\n}","preventionTips":["Route only file-upload endpoints through the multipart parser","Use curl -F or FormData clients so content type is correct","Reject GET/HEAD before parsing"],"tags":["multipart","node","http","content-type"],"backgroundTag":"multipart-content-type-invalid","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}