File Upload APIs 00:00:01 One request for a small object A connection fails after nine pieces of a large upload have reached storage. The user presses Resume. Should the service ask for nine pieces again, trust the user's progress bar, or check what the server actually accepted? The boundary separates the parts: here a text field and a file. It must not occur inside the data. The API passes the bytes on to storage while they arrive, and stops when the size limit is passed. There is no way to say which bytes arrived. The server throws the part away. For a photo that is fine. For a 2 GB video, 1.9 GB is sent again. A simple multipart form is often sufficient for a small file. Establish authentication, size limits and validation at the service even when the client has already performed its own early checks. 00:01:00 Split a large file into identified pieces A 100 MB file becomes 10 chunks of 10 MB, sent 3 at a time, then joined. The server makes an upload id and says: 10 chunks of 10 MB. Chunks 1, 2 and 3 travel together. Each carries its number and a checksum. Chunk 2 is done first, so chunk 4 starts. Progress counts finished chunks. Chunk 4 is lost. Only those 10 MB are sent again, after a short wait. Ten chunks are done. The order in which they came does not matter. The server checks that none is missing, checks the checksums and joins them. 1 start, 10 chunks, 1 complete: 12 requests. Independent parts can be transferred in parallel and retried. Bound concurrency so one user does not monopolize every connection, and verify the parts belong to this upload rather than merely sharing a number. 00:02:07 Resume from a confirmed offset The tus way: the server remembers how many bytes it has, and the client asks before it continues. The client says how big the file will be and gets an address for this upload. The bytes flow. The server stores them as they come. The server has 60 MB of 100 MB. The client is not sure, and does not need to be. After restarting, the client asks the server for the confirmed upload offset. The service reports sixty million bytes. That is where the next request can safely resume. It sends only the last 40 MB. If the offset it names is wrong, the server answers 409 and nothing is mixed up. Ask the server for its accepted offset or part inventory before continuing. A client's progress indicator may have counted bytes that left the phone but never became durable at the destination. 00:03:07 Delegate the transfer to storage The API gives out a short-lived permission slip. The bytes go straight to object storage. The client sends the name, size and type. The API checks who is asking and whether this is allowed. A row is written with status pending and a key we chose ourselves. The API computes a signed URL with its own storage key. No call to storage is needed. It lasts 15 minutes. The bytes never touch our servers. For big files each part gets its own signed URL. Storage sends an event. This works even if the client closes the page right after the upload. The scanner checks real size, type and viruses. Only then is the status ready and the file visible. A short-lived signed upload grant can let bytes bypass the application servers. Restrict it to the intended object and operation, and validate the completed object before making it available to readers. 00:04:07 Choose recovery before choosing a size Small and stable: one request is enough. A failure now costs real time, so split it. Above 100 MB, or on a network that drops, it must be able to continue. With high volume the bytes should skip our servers, whatever the method. Larger parts reduce per-request overhead but make each failed retry more expensive. The choice depends on link reliability, object size and the storage provider's documented constraints. 00:04:38 Finish the missing part and commit The client says complete, but chunk 7 never came. It lost track of chunk 7 after a crash. It answers with the missing number instead of making a broken file. Now it is whole. Sending a chunk twice is harmless, because its number is its identity. Completing an upload should verify its required parts and publish a stable completed object. Abandoned partial uploads also need a cleanup policy so resuming a legitimate transfer remains possible for the promised interval. A usable upload protocol distinguishes bytes that were sent, pieces durably acknowledged and a complete object safe to publish. Give the client a recovery path for each interrupted state.