Skip to content
Visit Stream on GitHub
Set theme to dark (⇧+D)

Upload video file

Basic Uploads (for small videos)

For files smaller than 200MB you can use simple form based uploads. This is an easy way to upload but does not support resumable uploading.

Make an HTTP request with content-type header set to multipart/form-data and include the media as an input with the name set to file.

cURL example

curl -X POST \-H "Authorization: Bearer $TOKEN" \-F file=@/Users/kyle/Desktop/video.mp4 \$ACCOUNT/stream

Resumable uploads with tus (for large files)

What is tus?

tus is a protocol based on HTTP for resumable file uploads. Resumable means that an upload can be interrupted at any moment and can be resumed without re-uploading the previous data again. An interruption may happen willingly, if the user wants to pause, or by accident in case of an network issue or server outage.

tus protocol is the recommended method for uploading large files to Cloudflare Stream from a computer. Popular programming languages have tus client implementations.

Specifying upload options

The tus protocol allows you to add optional parameters in the Upload-Metadata header.

Supported options in "Upload-Metadata"

  • requiresignedurls

    • If this key is present, the video playback for this video will be required to use signed urls after upload.
  • allowedorigins

  • thumbnailtimestamppct

    • Specify the default thumbnail timestamp percentage. Note that percentage is a floating point value between 0.0 and 1.0.
  • watermark

    • The watermark profile UID.

Command-line example

You will also need to download a tus client. This tutorial will use the tus python client, available through pip, pythons's package manager.

pip install -U
tus-upload --chunk-size 5242880 --header Authorization "Bearer $TOKEN" $PATH_TO_VIDEO$ACCOUNT/stream

In the beginning of the response from tus, you’ll see the endpoint for getting information about your newly uploaded video.

INFO Creating file endpointINFO Created:

Golang Example

To get started, import a tus client. You can use the go-tus by eventials to upload from your Go applications.

package main
import (    "net/http"    "os"
    tus "")
func main() {    accountID := "ACCOUNT ID"
    f, err := os.Open("videofile.mp4")
    if err != nil {        panic(err)    }
    defer f.Close()
    headers := make(http.Header)    headers.Add("Authorization", "Bearer $TOKEN")
    config := &tus.Config{        ChunkSize:           5 * 1024 * 1024, // Cloudflare Stream requires a minimum chunk size of 5MB.        Resume:              false,        OverridePatchMethod: false,        Store:               nil,        Header:              headers,        HttpClient:          nil,    }
    client, _ := tus.NewClient(""+ accountID +"/stream", config)
    upload, _ := tus.NewUploadFromFile(f)
    uploader, _ := client.CreateUpload(upload)

You can also get the progress of the upload if you're running the upload in a goroutine.

// returns the progress percentage.upload.Progress()
// returns whether or not the upload is complete.upload.Finished()

Please see go-tus on GitHub for functionality such as resuming uploads and getting more details about the progress of the upload.

Node.js Example

Install tus-js-client

npm install tus-js-client

Set up an index.js and configure:

  • API endpoint with your Cloudflare Account ID
  • Request headers to include a API token
var fs = require("fs");var tus = require("tus-js-client");
// specify location of file you'd like to upload belowvar path = __dirname + "/test.mp4";var file = fs.createReadStream(path);var size = fs.statSync(path).size;
var options = {  endpoint: "{ACCOUNT ID}/stream",  headers: {    'Authorization': 'Bearer $TOKEN',  },  chunkSize: 5 * 1024 * 1024, // Cloudflare Stream requires a minimum chunk size of 5MB.  resume: true,  metadata: {    filename: "test.mp4",    filetype: "video/mp4",    defaulttimestamppct: 0.5,    watermark: "$WATERMARKUID"  },  uploadSize: size,  onError: function (error) {    throw error;  },  onProgress: function (bytesUploaded, bytesTotal) {    var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);    console.log(bytesUploaded, bytesTotal, percentage + "%");  },  onSuccess: function () {    console.log("Upload finished:", upload.url);    var index = upload.url.lastIndexOf("/") + 1;    var mediaId = upload.url.substr(index)    console.log("Media id:", mediaId);  }};
var upload = new tus.Upload(file, options);upload.start();