Skip to main content

TUS Resumable Upload

Note

TUS resumable upload is in Public Beta and no SLA is provided. Evaluate it before using it in production.

TUS is an HTTP-based resumable upload protocol for large files and unreliable networks: the file is split into chunks and uploaded in sequence, so an interrupted transfer resumes from where it stopped instead of starting over.

For everyday small uploads, see Upload files.

When to use it​

  • Large files such as videos, design assets, and datasets, especially single files over 200 MB
  • Mobile networks or long-running uploads
  • Cases that need progress reporting plus pause and resume

Supported entry points​

Entry pointVersionUsage
JS SDK@cloudbase/js-sdk 3.11.1+bucket.uploadResumable(), see Use the JS SDK
Manager Node SDK@cloudbase/manager-node 5.10.6+app.storage.uploadObjectResumable(), see Use the Manager Node SDK
CLI@cloudbase/cli 3.9.5+tcb storage objects upload, see Use the CLI
HTTP APINot applicable; connect over the TUS protocolImplement a TUS client yourself; APIs are listed under Resumable

Use the JS SDK​

Use uploadResumable() from the JS SDK; it transfers data in chunks over the TUS protocol:

const bucket = app.storage.from('videos');

const task = bucket.uploadResumable('user-123/demo.mp4', file, {
chunkSize: 5 * 1024 * 1024,
onProgress: (loaded, total) => {
console.log(loaded, total);
},
});

const { data, error } = await task;
if (error) throw error;

Common options:

OptionDescription
chunkSizeChunk size. When omitted, it is derived from the file size (see below); when set manually, 1 MB to 60 MB, with a 4 MB cap in WeChat Mini Programs
retryDelaysRetry backoff in milliseconds; defaults to [0, 200, 500, 1500, 3000, 5000]
onProgressProgress callback with bytes uploaded and bytes total
abort(terminate?)Call task.abort() to stop the upload; terminate: true also asks the server to clean up

After an interruption, call uploadResumable() again with the same path and file to continue from the chunks already stored. For the full parameter and result reference, see uploadResumable.

How the chunk size is chosen​

When chunkSize is omitted, the SDK picks a chunk from the file size and limits it to 1 MB–60 MB:

File sizeChunk size
Under 30 MB6 MB
Under 100 MBFile size / 8
Under 500 MBFile size / 10
Under 1 GBFile size / 20
Under 10 GBFile size / 30
OtherwiseFile size / 50

An upload has at most 10000 parts. If the chunk above would produce more than 10000 parts, the SDK first raises the chunk size (up to 60 MB) to stay within the limit; if it still exceeds the limit, the upload is rejected before a session is created. A single file is limited to 100 GiB.

You rarely need to set it manually. Pass chunkSize explicitly only for unstable networks, finer progress granularity, or when debugging the upload path.

Use the Manager Node SDK​

For large uploads from a backend, use uploadObjectResumable() from the Manager Node SDK:

const res = await app.storage.uploadObjectResumable({
bucketId: 'videos',
objectName: 'big.mp4',
localPath: './big.mp4',
onProgress: (p) => {
console.log(`${Math.floor(p.percent * 100)}% (${p.loaded}/${p.total})`);
},
});

Differences from the JS SDK:

ItemNotes
File sourceAccepts only a local file path via localPath; no Buffer or streams
Chunk sizeChosen by the SDK from the file size; not configurable
ResumingCall again with the same parameters to continue from the breakpoint; a different upsert value counts as a different session
Pause or terminateabortSignal pauses by default; set terminateOnAbort: true to terminate and clean up fragments

For the full parameters and result, see uploadObjectResumable.

Use the CLI​

With tcb storage objects upload, files of 200 MB or more use resumable upload automatically; pass --resumable to force it for smaller files:

# 200 MB and above: resumable by default
tcb storage objects upload ./video.mp4 videos/video.mp4 -b my-bucket

# Force resumable upload for a small file
tcb storage objects upload ./video.mp4 videos/video.mp4 -b my-bucket --resumable

Press Ctrl+C to interrupt; uploaded chunks and the local resume record are kept, and re-running the same command continues from the breakpoint. Empty files do not support resumable upload and fall back to a normal upload. See Upload objects.

Cleaning up interrupted uploads​

When a chunked upload is interrupted, two kinds of leftovers remain in the bucket. Both count toward storage, and CloudBase does not clean them up automatically:

  • Fragments: chunks that were uploaded but never assembled
  • Incomplete objects: the object of the upload session, tagged Tus-Complete=false and set to true once the upload completes

Configure two lifecycle rules on the bucket, one for each kind. There are two ways to open the COS console for it:

  • From the CloudBase console: Cloud Storage → File management → Go to COS bucket in the top right
  • Open the URL directly: fill the bucket name into the link below. CloudBase storage is in Shanghai, so region is always ap-shanghai
https://console.cloud.tencent.com/cos/bucket?bucket=<BucketName>&region=ap-shanghai&type=basicconfig&anchorType=lifeCycle&isTcb=true

<BucketName> is the bucket name shown on the Cloud Storage file management page, for example 6c6f-lowcode-0gwpl9v4125156ef-1258057692; it already contains the APPID. Then go to "Basic Configuration → Lifecycle → Add Rule".

Rule 1: Delete fragments​

Removes chunks that were never assembled:

  1. Basic information: enable the rule and scope it to a specific range or the whole bucket
  2. Rule configuration: select delete fragments and set the number of days, for example delete 1 day after the fragment is created

Rule 2: Clean up incomplete objects by tag​

Filter objects that never finished uploading by tag, then delete them by modification time:

  1. Basic information: enable the rule, set the scope to "specified range", select object tag, and enter tag key Tus-Complete with value false
  2. Rule configuration: select "delete 1 day after the file is modified"

Objects tagged true have completed uploading and are not matched by this rule.

Once both rules take effect, interrupted fragments and incomplete objects are cleaned up gradually, while in-progress and completed objects are unaffected. See Configure lifecycle.