TUS Resumable Uploads

The resumable upload endpoint allows resumable and presigned uploads of video files. This allows end-users to upload directly to Bunny Stream and greatly improves reliability on poor networks and mobile connections.

The endpoint uses the open protocol for resumable file uploads called tus. Before a video can be uploaded through the tus endpoint a video object must be created through the Create Video call to obtain the video ID.

TUS Endpoint

https://video.bunnycdn.com/tusupload

Authentication

To authenticate a request, two headers must be passed with the tus upload.

  • AuthorizationSignature should contain the pre-generated SHA256 header
  • AuthorizationExpire should contain the UNIX timestamp of the upload expiration time
  • LibraryId should contain the library ID where the video should be placed
  • VideoId should contain the video ID of the previously created video object

Video Metadata Parameters

  • filetype should contain the file type of the uploaded video
  • title should contain the title of the video

Presigned Request Signature Generation

To generate the authorization signature, the following pseudo-function should be used:

sha256(library_id + api_key + expiration_time + video_id)

Upload Example JavaScript

// Create a new tus upload
var upload = new tus.Upload(file, {
    endpoint: "https://video.bunnycdn.com/tusupload",
    retryDelays: [0, 3000, 5000, 10000, 20000, 60000, 60000],
    headers: {
        AuthorizationSignature: "presigned_signature", // SHA256 signature (library_id + api_key + expiration_time + video_id)
        AuthorizationExpire: 1234567890, // Expiration time as in the signature,
        VideoId: "video-guid", // The guid of a previously created video object through the Create Video API call
        LibraryId: 1234567890,
    },
    metadata: {
        filetype: file.type,
        title: title,
    },
    onError: function (error) { },
    onProgress: function (bytesUploaded, bytesTotal) { },
    onSuccess: function () { }
})

// Check if there are any previous uploads to continue.
upload.findPreviousUploads().then(function (previousUploads) {
    // Found previous uploads so we select the first one. 
    if (previousUploads.length) {
        upload.resumeFromPreviousUpload(previousUploads[0])
    }

    // Start the upload
    upload.start()
})

TUS Documentation

For more documentation, code samples, and client implementations, you can visit the official tus website.