Design resumable file uploads: continue from the Tus server offset
A resumable upload continues from the position the server accepted after a connection failure, instead of sending the whole file again. Tus 1.0 defines an open protocol for doing this over HTTP. A client creates an upload resource, uses HEAD to read the current byte offset, then sends the remaining bytes with PATCH and Upload-Offset. Even with Tus, the service must design authentication, authorization, retention, and final file validation separately.
A resumable upload continues from the position the server accepted after a connection failure, instead of sending the whole file again. Tus 1.0 defines an open protocol for doing this over HTTP. A client creates an upload resource, uses HEAD to read the current byte offset, then sends the remaining bytes with PATCH and Upload-Offset. Even with Tus, the service must design authentication, authorization, retention, and final file validation separately.
Tus request flow
A client can first send OPTIONS to discover the server’s Tus-Version, supported extensions (Tus-Extension), and maximum size (Tus-Max-Size). This prevents clients from relying on features the server does not offer. Determine actual support from the deployed server’s response.
When the server supports the Creation extension, the client sends POST with the total size in Upload-Length to create an upload resource. On success, the server returns 201 Created and the resource URL in Location; the new resource starts at offset 0. If the file length is not yet known, the client can use Upload-Defer-Length: 1 only when the server advertises that extension.
The file bytes are sent as follows. The URL and sizes below are illustrative protocol values.
HEAD /files/upload-id
Tus-Resumable: 1.0.0
HTTP/1.1 200 OK
Upload-Offset: 70
Upload-Length: 100
Tus-Resumable: 1.0.0
PATCH /files/upload-id
Content-Type: application/offset+octet-stream
Upload-Offset: 70
Tus-Resumable: 1.0.0
[remaining 30 bytes]After a successful PATCH, the server returns 204 No Content and the new Upload-Offset. A client should not treat bytes as durably accepted merely because it sent them; it should use the offset confirmed by the server. If the connection drops or the response is lost, send HEAD to the same upload URL, read the actual stored position, and continue from there.
Offset conflicts and retries
In Tus, Upload-Offset is a non-negative byte position in the resource. The offset in a PATCH must exactly match the server’s current offset. Otherwise the server rejects the request with 409 Conflict and leaves the upload unchanged. This prevents duplicate continuation or overwriting from a stale position.
After an unexpected network error, do not guess progress or blindly resend the last block. Check with HEAD first and continue from the server’s offset. If supported, the Checksum extension can validate each PATCH body, but that does not replace business or safety validation of the completed file.
Policies the service must define
**Authentication and ownership:** The Tus specification leaves authentication and authorization to the implementation. Check on creation, inspection, patch, and deletion that the upload belongs to the current user or tenant. Knowing a `Location` URL alone must not grant access.
**Expiration and cleanup:** Interrupted uploads can occupy storage. If offering the Expiration extension, advertise it through `OPTIONS`, return `Upload-Expires`, and define `404` or `410` handling for expired URLs. Clean up both session metadata and temporary bytes.
**Size and resource limits:** Enforce the total size with `Tus-Max-Size` and server-side stream limits. Also manage per-user concurrent sessions, accumulated temporary storage, and idle time according to service needs.
**Consistency across distributed servers:** Behind a load balancer, all nodes must see the same offset and bytes, or requests must be routed to the right node. The Tus FAQ notes that sticky sessions or shared state/locking may be needed when reconnecting to another node. An offset held only in process memory can make resume fail after a restart or node change.
**Validation after completion:** Receiving all bytes does not prove that the file is safe or valid. Keep the temporary upload quarantined, inspect its actual type and content, and scan it as required before publication. Commit the final object atomically and clean up the upload session.
**Cancellation:** If the server supports the Termination extension, advertise it and release temporary storage and related resources for cancelled sessions. Closing a browser tab does not automatically delete the server session.
Tus Upload-Metadata can carry extra details such as a filename or type, but these are client-supplied values. Do not use them without validation to determine storage paths, authorization, or content classification. Tus does not assume uploads represent filesystem files, so the protocol itself does not guarantee a filename or media type.
Before adopting it
Does the client check the `OPTIONS` response for protocol version, extensions, and maximum size?
Does it use `HEAD` on resume and send `PATCH` from the offset the server reports?
Are `409` for offset mismatch and `412` for unsupported protocol version handled as distinct errors?
Are user/tenant permissions checked for upload URLs, without treating the URL itself as a credential?
Are expiration, cleanup, shared state across nodes, and cancellation defined?
Are file contents validated and atomically published after completion?
Are optional Tus extensions used only when the server advertises them?
Sources
[Tus Resumable Upload Protocol 1.0](https://tus.io/protocols/resumable-upload/1-0-x)
[Tus FAQ: resuming, use cases, expiration, and metadata](https://tus.io/faq)