Resumable PDF Uploads with tus.io: A Complete Guide
Anyone who has built a PDF upload feature knows the pain: PHP's upload_max_filesize cuts off the request, Nginx returns a 413, or a mobile user's connection drops halfway through a 50 MB file and they have to start all over. These are not edge cases — they are the norm when dealing with large documents.
FUNBREW PDF supports the tus.io resumable upload protocol. This guide walks through how it works, how to implement it, and what to keep in mind for production deployments.
Why Standard Multipart Uploads Fall Short
Traditional multipart/form-data uploads send the entire file in a single HTTP request. That design works fine for small files, but breaks down quickly at scale.
| Problem | Symptom |
|---|---|
| Server-side size limits | Nginx returns 413 above client_max_body_size (default 1 MB); PHP rejects files above upload_max_filesize (default 2 MB) |
| Proxy timeouts | Long-running uploads get killed by intermediate proxies |
| Network interruptions | Wi-Fi drops or mobile dead zones mean starting over |
| No progress feedback | Accurate upload progress is hard to surface in the UI |
These issues are particularly painful in enterprise workflows where users upload multi-hundred-megabyte PDFs from laptops on hotel Wi-Fi or from mobile devices in areas with spotty coverage.
What Is tus?
tus.io is an open protocol for resumable file uploads built on HTTP. The spec is published as version 1.0.0.
The core idea is straightforward: chunking plus offset tracking.
- The client sends a
POSTto reserve an upload slot; the server issues an upload key. - The client sends file data in chunks via
PATCH, each time specifying where it left off (Upload-Offset). - After an interruption, the client sends a
HEADto learn the current offset, then resumes from there.
Because each request carries only one chunk, keeping chunks below the limits along the path (such as Nginx's client_max_body_size) means the total file size is no longer bound by those limits. The PATCH body is the raw file data (application/offset+octet-stream), not a multipart/form-data file field, so PHP's upload_max_filesize does not apply. The server announces its overall limit in the Tus-Max-Size header of the OPTIONS response.
tus in FUNBREW PDF API
Endpoints
FUNBREW PDF implements tus protocol v1.0.0 with the following endpoints:
| Method | Path | Purpose |
|---|---|---|
OPTIONS |
/api/pdf/uploads |
Discover server capabilities and supported extensions |
POST |
/api/pdf/uploads |
Reserve an upload slot; returns Location with the upload key |
HEAD |
/api/pdf/uploads/{key} |
Get current Upload-Offset to find the resume point |
PATCH |
/api/pdf/uploads/{key} |
Write a chunk of data |
DELETE |
/api/pdf/uploads/{key} |
Cancel and discard an upload |
Authentication: Use your existing PDF API key (X-API-Key header, or Authorization: Bearer) — no additional credentials needed. The upload endpoints are not rate limited and not plan gated; limits apply on the processing APIs (merge, compress, and so on) that you pass the upload to.
File size limit: With the default configuration a single upload can be up to 5 GB. The actual value is in the Tus-Max-Size header of the OPTIONS response.
Key Headers
| Header | Direction | Description |
|---|---|---|
Tus-Resumable: 1.0.0 |
Request | Required by the spec on every request except OPTIONS; a different version gets 412 |
Upload-Length |
POST request | Total file size in bytes |
Upload-Offset |
PATCH request / HEAD response | Byte position to start writing / current received position. A mismatch with the server returns 409 |
Upload-Metadata |
POST request | Comma-separated key base64value pairs. Without filename (or name) the POST returns 400 |
Upload-Expires |
POST / PATCH response | When an unfinished upload will be discarded |
Content-Type: application/offset+octet-stream |
PATCH request | Required for all chunk write requests |
Implementation Examples
1. Raw Protocol with curl
Working through tus with curl first is the best way to understand what is actually happening.
export KEY="sk-your-api-key"
export BASE="https://pdf.funbrew.cloud"
export FILE="large-document.pdf"
FILE_SIZE=$(wc -c < "$FILE" | tr -d ' ')
# Upload-Metadata values are base64; use printf, because echo would encode the newline too
FILE_NAME_B64=$(printf '%s' "$(basename "$FILE")" | base64 | tr -d '\n')
# Step 1: Reserve an upload slot (POST)
LOCATION=$(curl -s -D - -o /dev/null -X POST "$BASE/api/pdf/uploads" \
-H "X-API-Key: $KEY" \
-H "Tus-Resumable: 1.0.0" \
-H "Upload-Length: $FILE_SIZE" \
-H "Upload-Metadata: filename $FILE_NAME_B64,filetype $(printf '%s' application/pdf | base64)" \
| grep -i "^location:" | tr -d '\r' | awk '{print $2}')
echo "Upload URL: $LOCATION"
# → https://pdf.funbrew.cloud/api/pdf/uploads/<UUID>
# Step 2: Send a chunk (PATCH)
# For clarity, this example sends the entire file in one chunk. If a proxy on the path
# limits the body size, send smaller chunks and continue from the returned Upload-Offset.
curl -i -X PATCH "$LOCATION" \
-H "X-API-Key: $KEY" \
-H "Tus-Resumable: 1.0.0" \
-H "Upload-Offset: 0" \
-H "Content-Type: application/offset+octet-stream" \
--data-binary @"$FILE"
# → 204 No Content
# Upload-Offset: <total_bytes>
# Step 3: After an interruption, check where we left off (HEAD)
# With curl, use -I for HEAD requests (-X HEAD makes curl wait for a body)
curl -I "$LOCATION" \
-H "X-API-Key: $KEY" \
-H "Tus-Resumable: 1.0.0"
# → 200 OK
# Upload-Offset: <bytes_received>
# Upload-Length: <total_bytes>
The offset from HEAD tells you exactly where to start the next PATCH. The trailing UUID of Location is the upload key you pass to the processing APIs later.
2. @funbrew/pdf-client SDK
The FUNBREW PDF browser SDK (not published on npm; served from https://pdf.funbrew.cloud/sdk/) wraps tus-js-client so you do not need to manage the protocol details manually.
Handle the API key with care: API keys issued in the dashboard have full permissions. A key embedded in a public web page can be read by anyone, so use this only on pages with restricted users (such as internal tools), or route requests through your own backend.
<!-- CDN — no bundler required -->
<script src="https://pdf.funbrew.cloud/sdk/pdf-client.umd.js"></script>
import { PdfClient } from 'https://pdf.funbrew.cloud/sdk/pdf-client.esm.js';
const client = new PdfClient({
baseUrl: 'https://pdf.funbrew.cloud',
apiKey: 'sk-your-api-key',
});
// Resumable upload; retries at the retryDelays intervals
const result = await client.uploadFile(file, {
chunkSize: 5 * 1024 * 1024, // 5 MB chunks (the SDK default)
onProgress: (sent, total) => {
const pct = ((sent / total) * 100).toFixed(1);
progressBar.style.width = `${pct}%`;
label.textContent = `${pct}%`;
},
});
console.log(result.key); // UUID — use this as upload_id in subsequent API calls
// Pass directly to a PDF processing endpoint
const compressed = await client.compress({
upload_id: result.key,
quality: 'medium',
});
console.log(compressed.download_url); // downloading it needs an API key with the download scope
TypeScript type definitions are available at https://pdf.funbrew.cloud/sdk/types/index.d.ts.
3. tus-js-client (Direct)
For more control over the upload behavior, use the official tus client directly.
npm install tus-js-client
import * as tus from 'tus-js-client';
interface UploadOptions {
file: File;
apiKey: string;
onProgress?: (percentage: number) => void;
onSuccess?: (uploadUrl: string) => void;
onError?: (error: Error) => void;
}
function startResumableUpload({
file,
apiKey,
onProgress,
onSuccess,
onError,
}: UploadOptions): tus.Upload {
const upload = new tus.Upload(file, {
endpoint: 'https://pdf.funbrew.cloud/api/pdf/uploads',
headers: { 'X-API-Key': apiKey },
// Keep chunks below any proxy body-size limit (5 MB, same as the SDK)
chunkSize: 5 * 1024 * 1024,
// Delays before each retry (ms); the array length is the max number of attempts
retryDelays: [0, 1000, 3000, 5000, 10000],
// filename is required by the server (the POST returns 400 without it)
metadata: {
filename: file.name,
filetype: file.type,
},
onProgress: (bytesUploaded, bytesTotal) => {
const pct = (bytesUploaded / bytesTotal) * 100;
onProgress?.(pct);
},
onSuccess: () => {
// upload.url holds the completed upload URL
// The trailing UUID segment is the upload key
onSuccess?.(upload.url ?? '');
},
onError: (error) => {
onError?.(error as Error);
},
});
// In browsers the upload URL is stored in Web Storage under the file's fingerprint
upload.findPreviousUploads().then((previousUploads) => {
if (previousUploads.length > 0) {
upload.resumeFromPreviousUpload(previousUploads[0]);
}
upload.start();
});
return upload;
// To cancel: upload.abort();
}
With findPreviousUploads() / resumeFromPreviousUpload(), a user who reloads the page and selects the same file again resumes from the last confirmed offset (unfinished uploads stay on the server until their Upload-Expires time).
Resume Flow Diagram
Here is what happens during a network interruption:
Client Server
| |
|-- POST /api/pdf/uploads ------→ | Reserve upload slot
|←-- 201, Location: /..../abc ---| Upload key issued
| |
|-- PATCH (offset=0, 5 MB) ----→ | Send chunk 1
|←-- 204, Upload-Offset: 5 MB --|
| |
|-- PATCH (offset=5 MB, 5 MB) -→ | Send chunk 2
~~~ Network drops ~~~
| |
| (Connection restored) |
|-- HEAD /..../abc -----------→ | Where did we stop?
|←-- 200, Upload-Offset: 8 MB --| 8 MB confirmed received
| |
|-- PATCH (offset=8 MB, ...) --→ | Resume from 8 MB
|←-- 204, Upload-Offset: total--| Complete
The numbers in the diagram are an example. The server records how many bytes it has received. A HEAD request gives the client that exact number, so there is never any ambiguity about where to resume.
Parallel Uploads (Concatenation Extension)
To send a large file in parallel, use the tus Concatenation extension. The client splits the file into N partial uploads, sends them in parallel, and then creates a final upload that the server joins into one file.
In tus-js-client, set parallelUploads. Note that metadata is attached only to the final upload; partial uploads get the values of metadataForPartialUploads. The FUNBREW PDF server requires filename on every POST, so put filename in metadataForPartialUploads too (otherwise the partial-upload POSTs return 400).
// tus-js-client parallel upload
const upload = new tus.Upload(file, {
endpoint: 'https://pdf.funbrew.cloud/api/pdf/uploads',
parallelUploads: 4, // four partial uploads sent in parallel
headers: { 'X-API-Key': apiKey },
metadata: { filename: file.name, filetype: file.type },
// partial uploads need a filename too (required by the server)
metadataForPartialUploads: { filename: file.name },
onSuccess: () => {
// the trailing segment of upload.url is the final upload key
console.log(upload.url?.split('/').pop());
},
});
upload.start();
The SDK's uploadFile() also has a parallelUploads option, but the SDK does not set a filename on partial uploads, so use tus-js-client directly for parallel uploads as shown above.
Limitation: When the server runs in S3 direct-streaming mode (s3-multipart), Concatenation is not available and POSTs with Upload-Concat return 400. If you get a 400, fall back to a single upload.
Webhook Notifications
To receive a server-side push when an upload finishes, subscribe to the tus events. They cannot be selected on the dashboard's webhook screen, so register them through the webhook management API (POST /api/webhooks; needs a key with the manage scope, SaaS edition and a plan with webhooks):
curl -X POST https://pdf.funbrew.cloud/api/webhooks \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/webhooks/funbrew", "events": ["tus.upload.completed", "tus.upload.aborted"]}'
# data.secret in the response is the signing secret (returned only here)
When an upload completes you will receive:
{
"event": "tus.upload.completed",
"timestamp": "2026-06-04T09:00:00.000000Z",
"data": {
"upload_key": "3f1c2a9e-8b7d-4e6f-9a01-2b3c4d5e6f70",
"original_filename": "quarterly-report.pdf",
"size": 15728640,
"storage": "local",
"s3_key": null,
"content_type": "application/pdf"
}
}
| Event | Fires when |
|---|---|
tus.upload.completed |
Final chunk received and the upload is complete |
tus.upload.aborted |
DELETE received, or the GC cleans up an expired unfinished upload |
content_type is set only when filetype was sent in Upload-Metadata (otherwise null). These events use the same signing, retry, and delivery-log infrastructure as pdf.generated events. See the PDF API Webhook Integration Guide for full details.
Piping Uploads Into PDF Processing
Once an upload is complete, pass its key directly to any PDF processing endpoint. No intermediate download and re-upload step is needed.
# Upload → merge two PDFs
curl -X POST https://pdf.funbrew.cloud/api/pdf/merge \
-H "X-API-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{
"upload_ids": ["3f1c2a9e-8b7d-4e6f-9a01-2b3c4d5e6f70", "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"],
"expiration_hours": 24
}'
# Upload → compress
curl -X POST https://pdf.funbrew.cloud/api/pdf/compress \
-H "X-API-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{"upload_id": "3f1c2a9e-8b7d-4e6f-9a01-2b3c4d5e6f70", "quality": "medium"}'
Supported endpoints: merge (upload_ids; 2 to 50 sources together with filenames), and compress, extract-text, to-image (upload_id; either it or filename, not both). They are SaaS-edition only, return 403 if the feature is not in your plan (the current Free, Pro and Business plans all include them), and need a key with the generate scope. An unfinished, unknown, or another company's upload key returns 422.
These endpoints are synchronous (they respond after processing). Each responds with an X-Job-Id header you can use to subscribe to SSE progress events (GET /api/pdf/jobs/{jobId}/events), which we cover in the SSE Progress Streaming Guide.
Production Considerations
Choosing a Chunk Size
One chunk is one request, so chunks must stay below any body-size limit of proxies on the path. The SDK default is 5 MB. Smaller chunks reduce how much is re-sent after an interruption but increase the number of requests. Tune together with retryDelays for your users' connections (tus-js-client on its own defaults to chunkSize: Infinity, i.e. the whole file in one request).
Garbage Collection
Upload state is stored with an expiry (about one day by default; see the Upload-Expires header), and a cleanup command that runs daily at 03:25 JST deletes expired entries. Completed uploads are also removed once they expire.
Pass the upload key to a processing endpoint as soon as the upload completes, and in any case before it expires.
Access Control
Each upload key is scoped to the company that created it. HEAD, PATCH, and DELETE requests from a different company return 404. The Open (single-tenant) edition has no company separation. Keys are UUIDs and are not guessable, but follow the API key management practices in the PDF API Production Guide for full security hygiene.
Nginx Configuration
If you relay tus requests to FUNBREW PDF through your own Nginx, check the relay's config (Nginx's client_max_body_size defaults to 1 MB and returns 413 above it):
# Example for relaying through your own server
location /api/pdf/uploads {
client_max_body_size 0; # 0 disables the body-size check (the client picks the chunk size)
proxy_request_buffering off; # Send the body upstream as it arrives (no temp file)
proxy_send_timeout 3600s; # How long a stalled send to upstream may last
proxy_read_timeout 3600s; # How long to wait for the upstream response
proxy_pass https://pdf.funbrew.cloud;
}
Note that the Location header will still point at FUNBREW PDF when relayed.
Summary
tus.io resumable uploads solve a class of problems that standard multipart uploads simply cannot handle gracefully.
- With chunks below the limits,
upload_max_filesizeandclient_max_body_sizeno longer bound the total file size - Network interruptions no longer mean starting over; uploads resume from the offset
- Chunk-level progress is easy to surface in the UI
- Completed uploads pipe directly into PDF processing endpoints
With the default configuration FUNBREW PDF accepts uploads up to 5 GB per file. Try upload-then-compress in the SDK Playground, PDF generation in the Playground, browse the API documentation, or see real-world patterns in the use cases section.
For deeper coverage of the JavaScript SDK — including PDF generation, SSE progress subscriptions, and the full TypeScript API surface — see the JS SDK guide.
Related Articles
- PDF API Production Guide 2026 — Rate limiting, observability, and cost management
- PDF API Webhook Integration Guide — Setting up and using webhook events
- SSE Progress Streaming Guide — Real-time job progress in the browser