{
  "id": "nextjs/server-action-formdata-multipart",
  "signature": "Error: Server Actions require the request body to be parsed as FormData or JSON. Received unexpected content type: multipart/form-data",
  "signature_zh": "错误：服务器操作要求将请求体解析为 FormData 或 JSON。收到意外的内容类型：multipart/form-data",
  "regex": "Received unexpected content type: multipart/form-data",
  "domain": "nextjs",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "A Server Action is called with a multipart/form-data request (e.g., from a file upload form without proper encoding), but Server Actions only support application/x-www-form-urlencoded, text/plain, or application/json content types. multipart/form-data is not supported.",
  "root_cause_type": "generic",
  "root_cause_zh": "服务器操作被调用时使用了 multipart/form-data 请求（例如，来自没有正确编码的文件上传表单），但服务器操作仅支持 application/x-www-form-urlencoded、text/plain 或 application/json 内容类型。不支持 multipart/form-data。",
  "versions": [
    {
      "version": "Next.js 14.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 14.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 14.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Multipart/form-data is the default for forms with file inputs, but Server Actions reject it; the form must be sent as URL-encoded or plain text.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the fetch still sends multipart/form-data (the default for FormData), the same error occurs. The fetch must explicitly set Content-Type to application/json.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "HTML forms do not support JSON enctype; the browser will ignore it and use the default (application/x-www-form-urlencoded for non-file forms, multipart/form-data for file forms).",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Remove the file input from the form and handle file uploads separately via an API route. Example: Use a standard form with action={serverAction} for text fields only, and add a separate file upload component that posts to /api/upload.",
      "success_rate": 0.9,
      "how": "Remove the file input from the form and handle file uploads separately via an API route. Example: Use a standard form with action={serverAction} for text fields only, and add a separate file upload component that posts to /api/upload.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Convert the form data to JSON in a client-side handler before calling the Server Action. Example: `const formData = new FormData(event.target); const json = Object.fromEntries(formData.entries()); await serverAction(json);`",
      "success_rate": 0.85,
      "how": "Convert the form data to JSON in a client-side handler before calling the Server Action. Example: `const formData = new FormData(event.target); const json = Object.fromEntries(formData.entries()); await serverAction(json);`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a third-party library like 'formidable' in an API route to handle multipart uploads, then call the Server Action from the API route with the parsed data as JSON.",
      "success_rate": 0.8,
      "how": "Use a third-party library like 'formidable' in an API route to handle multipart uploads, then call the Server Action from the API route with the parsed data as JSON.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "从表单中移除文件输入，并通过 API 路由单独处理文件上传。示例：仅对文本字段使用带有 action={serverAction} 的标准表单，并添加单独的文件上传组件，该组件向 /api/upload 发送 POST 请求。",
    "在调用服务器操作之前，在客户端处理程序中将表单数据转换为 JSON。示例：`const formData = new FormData(event.target); const json = Object.fromEntries(formData.entries()); await serverAction(json);`",
    "在 API 路由中使用第三方库（如 'formidable'）处理 multipart 上传，然后从 API 路由中使用解析后的数据以 JSON 格式调用服务器操作。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#formdata",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-01-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}