{"record":{"id":"5ecf899ea3b6e9ae","repo":"sveltejs/kit","slug":"invalid-data-for-file-reviver","errorCode":null,"errorMessage":"Invalid data for File reviver","messagePattern":"Invalid data for File reviver","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/shared.js","lineNumber":230,"sourceCode":"\t\t\t\t\tthrow new Error('Invalid data for Set reviver');\n\t\t\t\t}\n\t\t\t\tset.add(parse(item));\n\t\t\t}\n\n\t\t\treturn set;\n\t\t},\n\t\t/** @type {(value: any) => File} */\n\t\t[remote_file]: (value) => {\n\t\t\tif (\n\t\t\t\t!value ||\n\t\t\t\ttypeof value !== 'object' ||\n\t\t\t\ttypeof value.name !== 'string' ||\n\t\t\t\ttypeof value.type !== 'string' ||\n\t\t\t\ttypeof value.size !== 'number' ||\n\t\t\t\ttypeof value.lastModified !== 'number' ||\n\t\t\t\t!(value.data instanceof ArrayBuffer)\n\t\t\t) {\n\t\t\t\tthrow new Error('Invalid data for File reviver');\n\t\t\t}\n\n\t\t\tconst { data, name, ...meta } = value;\n\n\t\t\treturn new File([data], name, meta);\n\t\t}\n\t};\n\n\tconst all_revivers = { ...decoders, ...remote_fns_revivers };\n\n\t/** @type {(data: string) => unknown} */\n\tconst parse = (data) => devalue.parse(data, all_revivers);\n\n\treturn all_revivers;\n}\n\n/**\n * Stringifies the argument (if any) for a remote function in such a way that","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/shared.js#L212-L248","documentation":"File objects sent to remote functions are encoded as { data (ArrayBuffer), name, type, size, lastModified }. On the server, the File reviver validates every field before reconstructing a File. If any field is missing or of the wrong type, Kit throws this error instead of creating an invalid File.","triggerScenarios":"Calling a remote function with a File argument when the decoded payload lacks/wrongly types name, type, size, lastModified, or data — e.g. request body truncated, multipart/JSON bodies hand-assembled incorrectly, or client/server serialization versions mismatched.","commonSituations":"Large uploads cut off by proxy body-size limits (nginx client_max_body_size, platform limits); custom fetch wrappers that re-serialize the body; stale cached client code after upgrading Kit.","solutions":["Check proxy/server body size limits and raise them if large files are truncated","Align @sveltejs/kit versions and rebuild both client and server bundles","Send Files through the official remote-function client (do not pre-convert to JSON or FormData yourself)","Verify no middleware reads/re-parses the request body before Kit handles it"],"exampleFix":"// before (converting the File yourself)\nawait save({ file: { name: f.name, data: await f.arrayBuffer() } });\n// after (pass the File directly)\nawait save({ file });","handlingStrategy":"validation","validationCode":"function isEncodableFile(f) {\n  return f instanceof File &&\n    typeof f.name === 'string' && typeof f.type === 'string' &&\n    Number.isFinite(f.size) && Number.isFinite(f.lastModified);\n}\nif (!isEncodableFile(file)) throw new Error('Not a valid File to send to a remote function');","typeGuard":"const isFile = (v) => typeof File !== 'undefined' && v instanceof File &&\n  typeof v.name === 'string' && typeof v.size === 'number';","tryCatchPattern":"try {\n  await uploadFile(file);\n} catch (e) {\n  if (/Invalid data for File reviver/.test(e?.message ?? '')) {\n    alert('Upload failed — the file payload was truncated or malformed. Check body size limits.');\n  } else throw e;\n}","preventionTips":["Raise proxy body-size limits (e.g. nginx client_max_body_size) for uploads","Pass File objects directly to remote functions, never pre-serialized JSON","Align Kit versions across client and server","Keep file metadata intact — don't reconstruct partial File-like objects"],"tags":["serialization","file-upload","remote-functions"],"backgroundTag":"invalid-serialized-remote-argument","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}