Tutorials · 3 min read

Delegated video upload

Delegated uploads: Make video uploads with a token you create

Sometimes, it is desirable to allow users to upload videos into api.video. If using your private API key is not possible, you can use the delegated upload option. Learn how in this post!

Doug Sillars

September 16, 2020

At api.video, we offer a number of ways to upload video into your account. When you create and upload a video, the first step is to authenticate with your API, and generate an authentication token.

For a static website, it may not be feasible to create a new token on each page load. For instances like these, we offer a delegated upload token. This token works like a public key to your api.video account, allowing secure uploads without exposing your API key.

Generating a Delegated Upload Token

The first step in creating a delegated upload is to generate your token. First we authenticate with your private key :

Note: I am using the sandbox API endpoint AND my sandbox API key in this example. To use production, point to https://ws.api.video, and use your production key.

javascript

This will return a JSON response with your authentication token:

json

We’ll use this token to request the delegated upload token:

The delegated upload API will create a new token:

javascript

This will result in JSON response with the delegated access token:

{"token":"to1R5LOYV0091XN3GQva27OS"}

This token can now be used to upload videos into your api.video account. In the example below, I am uploading a video of clouds into my sandbox account.

javascript

Go ahead and try this yourself! Since the delegated upload is into my sandbox account, the video will be watermarked and deleted after 72 hours. Simply point the -F file@ to a video on your local file system, and it will be uploaded into my sandbox.

You'll receive a response similar to this:

json

These urls can be shared for others to watch your video. On opening the player link, you might see a video like this: (Note the video link in the JSON above has expired and will throw a 404 error).

video screenshot

Expiring Delegated tokens

Delegated tokens act like a public API - anyone with this token and the api.video url could upload videos into your account. For this reason, you can revoke delegated tokens so they can no longer be used.

Delegated Token Time To Live

In addition to expiration, you can also set a 'time to live' (TTL) when creating a token. Once the token expires, itc an no longer accept uploads. If you generate the token when the uplaod begins - you must ensure that at least one segment of the video is uploaded before the token expires, or the video will be rejected at the server. You can split the video with the JavaScript file API. Once the token expires, you'll have 24 hours to complete the rest of the upload (which should be PLENTY of time).

HTML

The API docs have a thorough explanation on how to build a form and upload a video.

Conclusion

Let us know how you are using delegated upload in your video service in our community forum

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.

Affordable

Volume discounts and usage-based pricing to ensure you don’t exceed your budget.