Resumable and large files (tus)
If you have a video over 200 MB, we recommend using the tus protocol ↗ for resumable file uploads. A resumable upload ensures that the upload can be interrupted and resumed without uploading the previous data again.
- Resumable uploads require a minimum chunk size of 5,242,880 bytes unless the entire file is less than this amount. For better performance when the client connection is expected to be reliable, increase the chunk size to 52,428,800 bytes.
- Maximum chunk size is 209,715,200 bytes.
- Chunk size must be divisible by 256 KiB (256x1024 bytes). Round your chunk size to the nearest multiple of 256 KiB. Note that the final chunk of an upload that fits within a single chunk is exempt from this requirement.
Before you can upload a video using tus, you will need to download a tus client.
For more information, refer to the tus Python client ↗ which is available through pip, Python's package manager.
Before you begin, import a tus client such as go-tus ↗ to upload from your Go applications.
The go-tus
library does not return the response headers to the calling function, which makes it difficult to read the video ID from the stream-media-id
header. As a workaround, create a Direct Creator Upload link. That API response will include the TUS endpoint as well as the video ID. Setting a Creator ID is not required.
You can also get the progress of the upload if you are running the upload in a goroutine.
Refer to go-tus ↗ for functionality such as resuming uploads.
Before you begin, install the tus-js-client.
Create an index.js
file and configure:
- The API endpoint with your Cloudflare Account ID.
- The request headers to include an API token.
The tus protocol allows you to add optional parameters in the Upload-Metadata
header ↗.
Setting arbitrary metadata values in the Upload-Metadata
header sets values in the meta key in Stream API.
-
name
- Setting this key will set
meta.name
in the API and display the value as the name of the video in the dashboard.
- Setting this key will set
-
requiresignedurls
- If this key is present, the video playback for this video will be required to use signed URLs after upload.
-
scheduleddeletion
- Specifies a date and time when a video will be deleted. After a video is deleted, it is no longer viewable and no longer counts towards storage for billing. The specified date and time cannot be earlier than 30 days or later than 1,096 days from the video's created timestamp.
-
allowedorigins
- An array of strings listing origins allowed to display the video. This will set the allowed origins setting for the video.
-
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.
Setting a creator value in the Upload-Creator
header can be used to identify the creator of the video content, linking the way you identify your users or creators to videos in your Stream account.
For examples of how to set and modify the creator ID, refer to Associate videos with creators.
When an initial tus request is made, Stream responds with a URL in the Location
header. While this URL may contain the video ID, it is not recommend to parse this URL to get the ID.
Instead, you should use the stream-media-id
HTTP header in the response to retrieve the video ID.
For example, a request made to https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream
with the tus protocol will contain a HTTP header like the following: