Tutorials · 4 min read

Video upload with cURL

api.video can help you simplify your video hosting and delivery. As such, one of the first things you'll want to do is to upload videos and get them loaded into the service. Once you upload the video, we'll take care of transcoding the video in to streams for delivery to your users.

Doug Sillars

March 19, 2020

api.video can help you simplify your video hosting and delivery. As such, one of the first things you'll want to do is to upload videos and get them loaded into the service. Once you upload the video, we'll take care of transcoding the video into streams for delivery to your users.

The easiest way to upload videos into api.video is using our API, and we'll walk through the steps to use the API and get your video online in this tutorial.

Using cURL

This tutorial uses curl and HTTP requests to authenticate your session, create a video, and then upload the video.

This example works for smaller videos, but as your video gets larger, you will want to break the video into smaller bites (bytes?) to facilitate upload. Here's how do to that using the command line.

Other languages?

We have many tutorials on video upload. Here are a few links to help you:

We have several Clients for additional platforms that will help you get started uploading videos quickly.

You can also check out the API reference documentation for uploading a video here:

Step 1

You need an access_token in order to create and upload a video.

You will need your API key to obtain the access_token. You can find your API key on your dashboard.

This tutorial uses the sandbox endpoint. To upload your video in production, simply replace all sandbox.api.video instances with ws.api.video.

First, call the authentication endpoint and get your access token.

Example - Curl Request

javascript

Example - Http Request

javascript

Example - Json Response

javascript

Step 2

We will use the create video API to create and upload the video.

The Authorization: Bearer header uses the access_token from the first step. Hint: Make sure to not remove the end ' when pasting in your token. The title parameter is required, so you must add a name to your video. If your video is hosted on a server, you can use "source":"url" in the JSON to add the video. If your video is on your local machine, we'll need to do one additional step.

This example also includes the video description. The response contains links to the video location, and generates a unique identifier videoId.

Curl Request

javascript

Http Request

javascript

Example Response

javascript

Step 3: Upload the video file.

In this step, we use the upload endpoint of the API. You can also use delegated tokens for the upload. The advantage of delegated tokens is that these are safe to use on a webpage (whereas your authorisation token is not), and the videos are directly uploaded to api.video. You can learn more about using delegated tokens for this same experience.

In Step 2, we saw how to link to a video already hosted. If the video is not hosted, and must be uploaded, we will call the video upload API:

javascript

When the upload is complete, a JSON response similar to that of step 2 is returned.

That's it - if you access the assets links in the response JSON - you can begin sharing the video you just created. Note: The mp4 URL is only added to the API response once the mp4 video has been encoded, which may take a few additional seconds.

Conclusion

In this post, we learned about authentication of our account with our api.video token, creating a video container, and uploading a video into that container. Once your video is uploaded, it is ready to be shared with your audience!

If you have any questions or suggestions, please share them on our commmunity forum. To start building now, singup for an api.video account here. Thanks for reading!

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.