Question presented to candidate: "Build a file uploader. Users drag files onto a drop zone or pick them with a button. Each file is uploaded in chunks, with a chunk size the user can choose. Show progress per file, let the user pause and resume, and retry chunks that fail. There is no real backend, so simulate the upload endpoint."
Requirements:
- A drop zone that highlights while files are dragged over it, plus a "Browse files" button for keyboard and mouse users.
- A chunk size selector (1 KB to 5 MB); each file is split with
Blob.sliceinto byte ranges. - A simulated endpoint with latency and occasional failures, plus an "offline" switch.
- Per-file progress (chunks done, percentage, a
progressbar), with Pause, Resume and Retry buttons. - Up to 2 chunks in flight per file; failed chunks retry with exponential backoff, and a file fails after a few attempts.
- When all chunks arrive, the server reassembles the file and the client checks that it matches.
What a strong answer should cover:
dragenter,dragover,dragleaveanddrophandling:preventDefaultondragover(ordropnever fires), and a depth counter so child elements do not flicker the highlight.- A framework-free upload controller: a chunk plan, a concurrency-limited pump, retry with backoff, and
AbortControllerfor pause. - Keeping controller objects out of render state, and rendering immutable snapshots.
- Resumability: only chunks not yet acknowledged are re-sent.
- Edge cases: a 0-byte file, the last short chunk, and cleanup on unmount.
Clarifying questions expected:
- "Does the real server support chunked or resumable uploads (for example S3 multipart or tus), and does it have a minimum part size?"
- "How many files and chunks may upload at once?"
- "Should pause survive a page reload?"
Code / implementation expected: Yes. The chunking and retry logic, the simulated server and the drop zone UI.