Skip to main content
The TUS resumable upload endpoint allows resumable and presigned uploads of video files. This enables end-users to upload directly to Bunny Stream and greatly improves reliability on poor networks and mobile connections. The endpoint uses the open tus protocol for resumable file uploads. Before a video can be uploaded through the TUS endpoint, a video object must be created through the Create Video API call to obtain the video ID.

TUS endpoint

How it works

  1. Create a video object using the Create Video API to get a videoId.
  2. Generate a presigned signature on your server using SHA256.
  3. Upload the file from the client using a TUS client library with the presigned credentials.
This approach allows secure direct uploads from end-users without exposing your API key.

Authentication

To authenticate a TUS upload request, the following headers must be included:

Video metadata parameters

The following metadata can be passed with the TUS upload:

Generating the signature

The authorization signature is generated by hashing the concatenation of several values using SHA256:
The signature must be generated on your server to keep your API key secure. Never expose your API key in client-side code.
A 401 Unauthorized from the TUS endpoint usually means one of: the AuthorizationExpire timestamp has passed before the upload finished, the AuthorizationSignature was generated with a different value than the request actually sends (mismatched library ID, API key, expiration, or video ID), or one of the LibraryId / VideoId headers is missing. The values used to generate the signature on your server must match the headers sent on the client byte-for-byte.

Examples

Once you have the presigned credentials from your server, use a TUS client library to upload the file. The official tus-js-client is recommended for browser uploads. Install the TUS client:

Basic client-side upload

Next.js App Router

This example shows a complete implementation using Next.js with the App Router.

React with Express backend

Express server (server.js):

Resuming uploads

One of the key benefits of TUS is the ability to resume interrupted uploads. The tus-js-client library handles this automatically:
The client stores upload progress in the browser’s local storage by default. If an upload is interrupted (due to network issues, browser refresh, etc.), it can be resumed from where it left off.

Error handling

Implement proper error handling to provide a good user experience:
Ensure any AuthorizationExpire timestamp is at least 1 hour (3600 seconds) or longer to make sure uploads are completed before authorization expires.