8.1 KiB
tus Resumable Upload Protocol (Condensed for Coding Agents)
Core Protocol
All Clients and Servers MUST implement the core protocol for resumable uploads.
Resuming an Upload
-
Determine Offset (HEAD Request):
- Request:
HEAD /files/{upload_id} HTTP/1.1 Host: tus.example.org Tus-Resumable: 1.0.0 - Response:
HTTP/1.1 200 OK Upload-Offset: {current_offset} Tus-Resumable: 1.0.0- Server MUST include
Upload-Offset. - Server MUST include
Upload-Lengthif known. - Server SHOULD return
200 OKor204 No Content. - Server MUST prevent caching:
Cache-Control: no-store.
- Server MUST include
- Request:
-
Resume Upload (PATCH Request):
- Request:
PATCH /files/{upload_id} HTTP/1.1 Host: tus.example.org Content-Type: application/offset+octet-stream Content-Length: {chunk_size} Upload-Offset: {current_offset} Tus-Resumable: 1.0.0 [binary data chunk] - Response:
HTTP/1.1 204 No Content Tus-Resumable: 1.0.0 Upload-Offset: {new_offset}Content-TypeMUST beapplication/offset+octet-stream.Upload-Offsetin request MUST match server's current offset (else409 Conflict).- Server MUST acknowledge with
204 No ContentandUpload-Offset(new offset). - Server SHOULD return
404 Not Foundfor non-existent resources.
- Request:
Common Headers
Upload-Offset: Non-negative integer. Byte offset within resource.Upload-Length: Non-negative integer. Total size of upload in bytes.Tus-Version: Comma-separated list of supported protocol versions (Server response).Tus-Resumable: Protocol version used (e.g.,1.0.0). MUST be in every request/response (exceptOPTIONS). If client version unsupported, server responds412 Precondition FailedwithTus-Version.Tus-Extension: Comma-separated list of supported extensions (Server response). Omitted if none.Tus-Max-Size: Non-negative integer. Max allowed upload size in bytes (Server response).X-HTTP-Method-Override: String. Client MAY use to override HTTP method (e.g., forPATCH/DELETElimitations).
Server Configuration (OPTIONS Request)
- Request:
OPTIONS /files HTTP/1.1 Host: tus.example.org - Response:
HTTP/1.1 204 No Content Tus-Resumable: 1.0.0 Tus-Version: 1.0.0,0.2.2,0.2.1 Tus-Max-Size: 1073741824 Tus-Extension: creation,expiration- Response MUST contain
Tus-Version. MAY includeTus-ExtensionandTus-Max-Size. - Client SHOULD NOT include
Tus-Resumablein request.
- Response MUST contain
Protocol Extensions
Clients SHOULD use OPTIONS request and Tus-Extension header for feature detection.
Creation (creation extension)
Create a new upload resource. Server MUST add creation to Tus-Extension.
- Request (POST):
POST /files HTTP/1.1 Host: tus.example.org Content-Length: 0 Upload-Length: {total_size} OR Upload-Defer-Length: 1 Tus-Resumable: 1.0.0 Upload-Metadata: filename {base64_filename},is_confidential- MUST include
Upload-LengthorUpload-Defer-Length: 1. - If
Upload-Defer-Length: 1, client MUST setUpload-Lengthin subsequentPATCH. Upload-Length: 0creates an immediately complete empty file.- Client MAY supply
Upload-Metadata(key-value pairs, value Base64 encoded). - If
Upload-LengthexceedsTus-Max-Size, server responds413 Request Entity Too Large.
- MUST include
- Response:
HTTP/1.1 201 Created Location: {upload_url} Tus-Resumable: 1.0.0- Server MUST respond
201 Createdand setLocationheader to new resource URL. - New resource has implicit offset
0.
- Server MUST respond
Headers
Upload-Defer-Length:1. Indicates upload size is unknown. Server addscreation-defer-lengthtoTus-Extensionif supported.Upload-Metadata: Comma-separatedkey valuepairs. Key: no spaces/commas, ASCII. Value: Base64 encoded.
Creation With Upload (creation-with-upload extension)
Include initial upload data in the POST request. Server MUST add creation-with-upload to Tus-Extension. Depends on creation extension.
- Request (POST):
POST /files HTTP/1.1 Host: tus.example.org Content-Length: {initial_chunk_size} Upload-Length: {total_size} Tus-Resumable: 1.0.0 Content-Type: application/offset+octet-stream Expect: 100-continue [initial binary data chunk]- Similar rules as
PATCHapply for content. - Client SHOULD include
Expect: 100-continue.
- Similar rules as
- Response:
HTTP/1.1 201 Created Location: {upload_url} Tus-Resumable: 1.0.0 Upload-Offset: {accepted_offset}- Server MUST include
Upload-Offsetwith accepted bytes.
- Server MUST include
Expiration (expiration extension)
Server MAY remove unfinished uploads. Server MUST add expiration to Tus-Extension.
- Response (PATCH/POST):
HTTP/1.1 204 No Content Upload-Expires: Wed, 25 Jun 2014 16:00:00 GMT Tus-Resumable: 1.0.0 Upload-Offset: {new_offset} Upload-Expires: Datetime in RFC 9110 format. Indicates when upload expires. Client SHOULD use to check validity. Server SHOULD respond404 Not Foundor410 Gonefor expired uploads.
Checksum (checksum extension)
Verify data integrity of PATCH requests. Server MUST add checksum to Tus-Extension. Server MUST support sha1.
- Request (PATCH):
PATCH /files/{upload_id} HTTP/1.1 Content-Length: {chunk_size} Upload-Offset: {current_offset} Tus-Resumable: 1.0.0 Upload-Checksum: {algorithm} {base64_checksum} [binary data chunk] - Response:
204 No Content: Checksums match.400 Bad Request: Algorithm not supported.460 Checksum Mismatch: Checksums mismatch.- In
400/460cases, chunk MUST be discarded, upload/offset NOT updated.
Tus-Checksum-Algorithm: Comma-separated list of supported algorithms (Server response toOPTIONS).Upload-Checksum:{algorithm} {Base64_encoded_checksum}.
Termination (termination extension)
Client can terminate uploads. Server MUST add termination to Tus-Extension.
- Request (DELETE):
DELETE /files/{upload_id} HTTP/1.1 Host: tus.example.org Content-Length: 0 Tus-Resumable: 1.0.0 - Response:
HTTP/1.1 204 No Content Tus-Resumable: 1.0.0- Server SHOULD free resources, MUST respond
204 No Content. - Future requests to URL SHOULD return
404 Not Foundor410 Gone.
- Server SHOULD free resources, MUST respond
Concatenation (concatenation extension)
Concatenate multiple partial uploads into a single final upload. Server MUST add concatenation to Tus-Extension.
- Partial Upload Creation (POST):
POST /files HTTP/1.1 Upload-Concat: partial Upload-Length: {partial_size} Tus-Resumable: 1.0.0Upload-Concat: partialheader.- Server SHOULD NOT process partial uploads until concatenated.
- Final Upload Creation (POST):
POST /files HTTP/1.1 Upload-Concat: final;{url_partial1} {url_partial2} ... Tus-Resumable: 1.0.0Upload-Concat: final;{space-separated_partial_urls}.- Client MUST NOT include
Upload-Length. - Final upload length is sum of partials.
- Server MAY delete partials after concatenation.
- Server MUST respond
403 ForbiddentoPATCHrequests against final upload.
concatenation-unfinished: Server adds toTus-Extensionif it supports concatenation while partial uploads are in progress.- HEAD Request for Final Upload:
- Response SHOULD NOT contain
Upload-Offsetunless concatenation finished. - After success,
Upload-OffsetandUpload-LengthMUST be equal. - Response MUST include
Upload-Concatheader.
- Response SHOULD NOT contain
- HEAD Request for Partial Upload:
- Response MUST contain
Upload-Offset.
- Response MUST contain