Batch Upload

Batch video upload using a bash script

In this tutorial, we will set up a script to upload a large number of videos.. Even though you can upload your videos through the Cloudflare Dashboard, we recommend using the command line terminal for mass operations.

To make API requests you will need your Cloudflare API key, your email address and one of your Cloudflare account ID.

You will also need to download a tus client. Tus is an open source protocol that Cloudflare uses to upload large files, such as your videos. This tutorial will use the tus python client, available through pip, pythons’s package manager. You can get help from the Python documentation.

pip install -U

This script assumes you are using bash terminal on Mac or Linux and have find and sed command available. It will find all files ending in .mp4 within a directory and upload them to Stream.

IFS=$'\n'; set -f
for f in $(find /{upload-directory} -name '*.mp4')
echo "now uploading $f"
tus-upload --header X-Auth-Key {api-key} --header X-Auth-Email {email} "$f"{account_id}/media --chunk-size 5242880 2>&1 | grep 'Created' | sed -n -e 's:^.*media\/::p'
unset IFS; set +f

Output will look like:

now uploading /Users/myuser/Desktop/example.mp4
now uploading /Users/myuser/Desktop/movies/movie1.mp4
now uploading /Users/myuser/Desktop/movies/movie2.mp4

Using the video ID returned after each upload, you can view each video at{VIDEO-ID}