{"record":{"id":"b55ce54a3bc5aa1b","repo":"sveltejs/kit","slug":"your-form-contains-input-type-file-fields-but","errorCode":null,"errorMessage":"Your form contains <input type=\"file\"> fields, but is missing the necessary `enctype=\"multipart/form-data\"` attribute. This will lead to inconsistent behavior between enhanced and native forms. For more details, see https://github.com/sveltejs/kit/issues/9819.","messagePattern":"Your form contains <input type=\"file\"> fields, but is missing the necessary `enctype=\"multipart/form-data\"` attribute\\. This will lead to inconsistent behavior between enhanced and native forms\\. For more details, see https://github\\.com/sveltejs/kit/issues/9819\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/forms/client.js","lineNumber":132,"sourceCode":"\t\tevent.preventDefault();\n\n\t\tconst action = new URL(\n\t\t\t// We can't do submitter.formAction directly because that property is always set\n\t\t\tevent.submitter?.hasAttribute('formaction')\n\t\t\t\t? /** @type {HTMLButtonElement | HTMLInputElement} */ (event.submitter).formAction\n\t\t\t\t: clone(form_element).action\n\t\t);\n\n\t\tconst enctype = event.submitter?.hasAttribute('formenctype')\n\t\t\t? /** @type {HTMLButtonElement | HTMLInputElement} */ (event.submitter).formEnctype\n\t\t\t: clone(form_element).enctype;\n\n\t\tconst form_data = new FormData(form_element, event.submitter);\n\n\t\tif (DEV && enctype !== 'multipart/form-data') {\n\t\t\tfor (const value of form_data.values()) {\n\t\t\t\tif (value instanceof File) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'Your form contains <input type=\"file\"> fields, but is missing the necessary `enctype=\"multipart/form-data\"` attribute. This will lead to inconsistent behavior between enhanced and native forms. For more details, see https://github.com/sveltejs/kit/issues/9819.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst controller = new AbortController();\n\n\t\tlet cancelled = false;\n\t\tconst cancel = () => (cancelled = true);\n\n\t\tconst callback =\n\t\t\t(await submit({\n\t\t\t\taction,\n\t\t\t\tcancel,\n\t\t\t\tcontroller,\n\t\t\t\tformData: form_data,\n\t\t\t\tformElement: form_element,","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/forms/client.js#L114-L150","documentation":"When a form contains file inputs but lacks enctype=\"multipart/form-data\", the native (non-enhanced) submission and the enhanced FormData-based submission send data differently. SvelteKit throws in dev to surface this inconsistency, which otherwise silently corrupts or drops uploads depending on enhancement.","triggerScenarios":"In DEV, handle_submit builds FormData from the form, enctype is not multipart/form-data, and any FormData value is a File instance (i.e. the form has <input type=\"file\"> used during submission).","commonSituations":"Adding an upload input to an existing form without updating enctype (the HTML default is application/x-www-form-urlencoded), forgetting the attribute after copying a form snippet, or conditionally rendered file inputs.","solutions":["Add enctype=\"multipart/form-data\" to the <form> tag containing the file input","Verify the form method is POST (required for multipart)","If files are optional, still set multipart enctype so enhanced and native submissions agree","Reference issue #9819 for the underlying behavior differences"],"exampleFix":"// before\n<form method=\"POST\" use:enhance>\n  <input type=\"file\" name=\"doc\">\n// after\n<form method=\"POST\" enctype=\"multipart/form-data\" use:enhance>\n  <input type=\"file\" name=\"doc\">","handlingStrategy":"validation","validationCode":"if (form.querySelector('input[type=file]') && form.enctype !== 'multipart/form-data') {\n  form.setAttribute('enctype', 'multipart/form-data');\n}","typeGuard":"const hasFilesWithoutMultipart = (form) =>\n  !!form.querySelector('input[type=file]') && form.enctype !== 'multipart/form-data';","tryCatchPattern":"try {\n  await handleSubmit(form);\n} catch (e) {\n  if (e.message.includes('multipart/form-data')) {\n    form.setAttribute('enctype', 'multipart/form-data');\n  } else throw e;\n}","preventionTips":["Set enctype=\"multipart/form-data\" on every form containing file inputs","Keep method=\"POST\" alongside multipart enctype","Re-check forms after adding conditional file inputs","Test both enhanced and disabled-JS submissions for upload forms"],"tags":["sveltekit","forms","file-upload","dev-only"],"backgroundTag":"form-missing-multipart-enctype","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}