Adding smart uploading so my spotty internet stops annoying me.
A big file doesn’t upload in one go. It goes up as numbered pieces called parts (the jargon is a multipart upload), and storage glues them together at the end. If one part fails, you only resend that part.
Retrying a failed part while your browser tab is still open is easy. The part that actually makes you want to throw your laptop is when your internet drops, or you accidentally close the tab 70% into a giant raster upload, and the browser forgets which parts already made it to the server - even though those gigabytes are sitting right there in R2.
A progress bar that only remembers “70%” is useless after a refresh. To actually resume, the browser has to write down three things together: which file it was, which upload it belongs to (the upload ID storage handed out at the start), and which parts storage has confirmed. Sarkoa keeps that note in IndexedDB, a small database the browser stores on your own computer, so it is still there after the tab closes.
Picking a chunk size
Under R2’s multipart limits, every part except the last has to be at least 5 MiB, with a ceiling of 10,000 parts total. It’s a classic trade-off: smaller parts mean less wasted data when your connection drops mid-part; larger parts mean fewer requests overall. The test below uses 8 MiB parts.
Don’t trust the browser’s memory alone
Even with IndexedDB, the browser’s note can get wiped or fall behind what R2 actually received (a part can land in storage a moment before the browser gets to write that down). So on resume the uploader doesn’t only read its own note. It also asks R2 directly: “which parts of this upload do you already have?”
I ran a quick check with a 26 MiB file split into four parts (8, 8, 8, and 2 MiB) under two scenarios (recorded requests and test conditions):
| Starting record | Parts sent on resume | Bytes sent on resume |
|---|---|---|
| Browser checkpoint contained parts 1 and 2 | 3 and 4 | 10 MiB |
| Browser checkpoint empty, storage reported parts 1, 2 and 3 | 4 | 2 MiB |
In the second run, the local checkpoint was completely empty, yet asking R2 what it already had let the uploader skip parts 1–3 and only send the final 2 MiB. (One browser quirk still applies in the real world: after a full tab close, the browser won’t let JavaScript silently re-read your hard drive, so you still have to re-select the file before it can pick up where it left off.)