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.

Create an api.video account

If you already have an account, you can skip this step.

Before you can start uploading your first video, you need to create an api.video account.

Once you are logged in to the Dashboard, select the environment of your choice (sandbox or production) and copy your API key.

Copy your API key through the dashboard

Copy your API key through the dashboard

You'll be able to find your API key in the dashboard dashboard.api.video.

There are separate API keys for Sandbox and Production environment.

In production, you can also manage multiple API keys from your dashboard, for different applications.

Generate the Upload Token

We will use the delegated upload API in order to generate our token. In this example, we will use curl to make the requests, however, you will find examples and code snippets with various programming languages using api.video API client libraries in our documentation.

bash

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.

bash

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).

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

Delegated upload offers a user-friendly method for video uploads, allowing the creation of tokens with specified expiration. This method is ideal for one-time video uploader solutions and quick content uploads without immediate metadata concerns.

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.