{"record":{"id":"f85763cf1c8dcb6f","repo":"sveltejs/kit","slug":"your-form-contains-input-type-file-fields-but-f85763","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":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/client/remote-functions/form.svelte.js","lineNumber":841,"sourceCode":"}\n\n/**\n * @param {FormData} form_data\n * @param {string} enctype\n */\nfunction validate_form_data(form_data, enctype) {\n\tfor (const key of form_data.keys()) {\n\t\tif (/^\\$[.[]?/.test(key)) {\n\t\t\tthrow new Error(\n\t\t\t\t'`$` is used to collect all FormData validation issues and cannot be used as the `name` of a form control'\n\t\t\t);\n\t\t}\n\t}\n\n\tif (enctype !== 'multipart/form-data') {\n\t\tfor (const value of form_data.values()) {\n\t\t\tif (value instanceof File) {\n\t\t\t\tthrow new Error(\n\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);\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":823,"sourceCodeEnd":848,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/client/remote-functions/form.svelte.js#L823-L848","documentation":"When a remote form's enctype is not multipart/form-data but the submitted FormData contains File values, enhanced and native submissions would behave inconsistently (native forms would silently drop or mis-encode files). SvelteKit throws in validate_form_data to surface this mismatch early.","triggerScenarios":"Adding <input type=\"file\"> to a <form> whose enctype remains the default application/x-www-form-urlencoded (or is unset), then submitting the enhanced remote form.","commonSituations":"Retrofitting a file upload into an existing text-only form without updating enctype; forgetting enctype on forms that grew file inputs over time; see sveltejs/kit#9819.","solutions":["Add enctype=\"multipart/form-data\" to the <form> element","Remove the file input if file upload is not intended","Handle the file via a separate upload endpoint/form with the correct enctype"],"exampleFix":"// before\n<form method=\"POST\" use:enhance>\n  <input type=\"file\" name=\"doc\" />\n</form>\n// after\n<form method=\"POST\" enctype=\"multipart/form-data\" use:enhance>\n  <input type=\"file\" name=\"doc\" />\n</form>","handlingStrategy":"validation","validationCode":"function needsMultipart(form) {\n  return form.enctype !== 'multipart/form-data' &&\n    form.querySelectorAll('input[type=\"file\"]').length > 0;\n}\n// if true, set enctype before submit","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add enctype=\"multipart/form-data\" whenever a form contains file inputs","Re-check enctype after adding file inputs to existing forms","Cover file-upload forms with a submit test"],"tags":["formdata","file-upload","enctype","remote-forms"],"backgroundTag":"missing-multipart-enctype","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}