sveltejs/kit · error

incomplete file data

Error message

incomplete file data

What it means

When reading a large uploaded file from a range/response stream, the File streamer yields chunks and asserts the total bytes received equals the declared file size. If the stream ends before size bytes arrive (truncated upload or dropped connection), it throws 'incomplete file data'.

Source

Thrown at packages/kit/src/runtime/form-utils.js:462

			size,
			this.lastModified,
			this.#get_chunk,
			this.#offset + start
		);

		return file;
	}
	stream() {
		const range = read_range(this.#get_chunk, this.#offset, this.size);
		const size = this.size;
		return stream_from_iterable(
			(async function* () {
				let cursor = 0;
				for await (const chunk of range) {
					cursor += chunk.byteLength;
					yield chunk;
				}
				if (cursor < size) throw new Error('incomplete file data');
			})()
		);
	}
	async text() {
		return text_decoder.decode(await this.arrayBuffer());
	}
}

const path_regex = /^[a-zA-Z_$]\w*(\.[a-zA-Z_$]\w*|\[\d+\])*$/;

/**
 * @param {string} path
 */
export function split_path(path) {
	if (!path_regex.test(path)) {
		throw new Error(
			`Invalid field name ${path}` +
				(DEV

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Retry the upload from the client, ideally with resumable/chunked upload support.
  2. Verify the client sent the complete body (check Content-Length vs received bytes) and that no proxy terminated the stream.
  3. If using a custom range source, ensure it yields exactly `size` bytes.

Example fix

// before
const data = await file.arrayBuffer(); // throws on truncated stream
// after
try {
  const data = await file.arrayBuffer();
} catch (e) {
  if (e.message === 'incomplete file data') return fail(400, { error: 'Upload truncated, please retry' });
  throw e;
}
Defensive patterns

Strategy: retry

Try / catch

try {
  const buf = await file.arrayBuffer();
} catch (e) {
  if (e.message === 'incomplete file data') {
    // prompt client to re-upload / resume
  } else throw e;
}

Prevention

When it happens

Trigger: A client aborts or drops the network connection mid-upload of a large file; server-side truncation; storage/range source returning fewer bytes than the advertised size.

Common situations: Flaky mobile connections during large binary form uploads; proxies or CDNs cutting long-running uploads; misbehaving custom range/storage backends reporting a larger size than they serve.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/7c0a23678e628581. Report an issue: GitHub.