Client-Side Upload Mechanics: The File Handle, Not the File

Quick reframe: what "select a file" actually hands over

When you pick a video in a browser (<input type="file">, drag-and-drop) or a native upload client, you do not get a copy of the video loaded into memory — a multi-gigabyte file would make that impractical on the spot. What you get is a lightweight file handle: a reference (in browsers, a File object; in a native app, an open file descriptor or a stored path) plus a snapshot of metadata captured at that instant — name, size, last-modified timestamp. The actual bytes are read lazily, in small buffered slices, exactly when a chunk is about to go out over the wire — not before. This is the client-side mirror of the server-side design in the storage deep-dive: neither side ever holds "the whole file" in memory at once, both stream it incrementally.

The consequence: the client's ability to resume depends on that handle still resolving to the same bytes, hours later — not on anything the server does or can enforce.

Why / The Problem

The Upload part’s protocol lets the client walk away from a dropped connection and resume from exactly the byte offset the server last acknowledged. But "resume from offset X" is only possible if the client can still hand the server "everything from byte X onward" — which means the file has to still exist, still be readable, and still be the same bytes it was when the session started. A resumable-upload protocol that's airtight on the server side is still only as resumable as the weakest link on the client side, and that link is a handle to something living on a laptop's disk, outside the protocol's control.

How It Works

Case 1 — the file moves, but stays on the same disk. On POSIX filesystems (macOS, Linux), a rename or move within the same volume is purely a directory-entry change — the underlying inode is untouched. An already-open file descriptor keeps reading correctly regardless of what the path now says; even a fresh open-by-path would still find the file, just at its new location. Practically, this means moving the video into a different folder mid-upload is usually harmless — if the uploader is holding a live handle rather than repeatedly re-resolving a remembered path. Browser behavior here isn't uniformly specified across engines — some re-validate the file's identity (size/last-modified) before a resumed read and will surface a read error if anything changed, even if the move itself was harmless. Treat "same volume, same bytes" as usually fine, not guaranteed fine.

Case 2 — the file moves across disks/volumes, or gets deleted. A cross-volume move is implemented as copy-then-delete-original, not a rename — so once the delete happens, the original handle/path is gone. Any attempt to read the next chunk fails client-side (a read / NotFoundError-class failure). This is a client-side failure only: the server's session record is completely unaffected, still durably holding every byte it already received. The upload doesn't "fail" on the server — it just stalls forever, waiting on a client that can no longer supply the rest.

Case 3 — you point the same session at a different file. This is the one the protocol actively defends against, not just tolerates. The total size (TOTAL in Content-Range: bytes START-END/TOTAL) is fixed the moment the session is created. A different-sized file trips a mismatch on the very next request. A same-sized-but-different file is subtler: pure byte-offset accounting can't detect that the content changed, only whether the count still adds up — offset arithmetic verifies quantity, not identity. Whatever protects against that lives one layer up, as whole-object hash verification at finalize (if the client supplied one at session creation) — meaning content corruption or substitution surfaces only after every byte has already been sent, and the fix is re-uploading the whole object, since a whole-object hash can't tell you which chunk was the problem.

Reconciling client-side belief against server-side truth
Reconciling client-side belief against server-side truth

This is why the resume flow in the Upload part always asks the server first (308 Resume Incomplete + Range) instead of the client just picking up from whatever offset it last remembers locally — the client's own bookkeeping is a belief, kept only for deciding what to try next, and it's the server's answer, not the client's memory, that's authoritative.

Case 4 — the session URI itself is lost. The session URI (returned once, from the initial POST) is the only handle that lets any future request address this specific in-progress upload — there's no way to look up "the upload this laptop was doing earlier" by any other means. If the browser tab is closed, the app is force-quit, or the device restarts before that URI is persisted somewhere durable on the client (localStorage, an app-local database), it's gone — even though the server is still faithfully holding every byte already received. The result is an orphaned session: real durable storage, real acknowledged bytes, permanently unreachable, until the session's TTL expires server-side (Google's public resumable-upload documentation states these session URIs commonly expire around one week after creation) and it's garbage-collected. A production-quality uploader persists the session URI keyed to something that identifies the file (name + size + last-modified, or a content hash) specifically so that re-selecting the same file later can look up "was I already mid-upload on this?" instead of silently starting over from zero.

Other challenges, briefly

ChallengeWhat breaksHow it's handled
Network interface change mid-upload (wifi → cellular)The TCP connection diesIndistinguishable from any other drop — a fresh connection, same session URI, same status-check-then-resume flow from the Upload part. The new connection doesn't need to be "the same network," only able to reach the same session URI.
Reading a multi-GB file without exhausting device RAMLoading the whole file at onceSame streamed/buffered-read discipline as the server's append-only write path (storage deep-dive) — read in fixed-size slices timed to chunk boundaries, never the whole file at once.
Two tabs/devices uploading the same fileTwo independent sessions, two independent durable objects — an unintended duplicate videoNot prevented by the resumable-upload protocol itself — it has no concept of "this is the same content as that other session." Preventing it is an application-layer job (disable the control, check local resume-state before issuing a fresh POST).
Many clients dropping at once (shared network outage) and all retrying immediatelyA retry storm hitting the upload service at the same instantStandard fix, not YouTube-specific: exponential backoff with jitter before a client re-issues its status-check/PUT, so retries spread out instead of syncing up.

The Invariants

  • Guarantees: Whatever the server has already durably acknowledged (the Upload part’s storage deep-dive) stays intact and unaffected by anything that subsequently happens to the client's local file — there's no path by which a client-side failure corrupts already-accepted server state.
  • Does not guarantee: That an interrupted upload is always resumable. Resuming requires two things the server has zero control over: the client must still be able to reproduce the exact same bytes from the acknowledged offset onward, and the client must still know the session URI. Lose either one, and the only way forward is a brand-new session starting at byte 0 — even though the old session's durable partial bytes still exist, unreachable, until they expire.