Direct Upload API
Uploading videos via the Viddler API has always been a bit of a roundabout process: first, the video has to be uploaded to your server, then you have to take that video file and upload it again to us, leaving lots of room for something to go wrong. Plus, there really isn’t any reason why a file should have to go you before it comes to us. That’s why I’m super excited to announce our brand new Direct Upload API, which allows you to point an upload form directly at our servers and skip all the steps in-between.
In order to start using it, all you need to do is call the viddler.videos.prepareUpload method (using our V2 API), point your form at the endpoint returned, and include the upload token as a hidden field. Here’s a quick example using PHPViddler:
<?php
include('phpviddler.php');
$user = 'YOUR USERNAME';
$pass = 'YOUR PASSWORD';
$api_key = 'YOUR API KEY';
$callback_url = 'CALLBACK';
$v = new Viddler_V2($api_key);
// Get a sessionid
$auth = $v->viddler_users_auth(array('user' => $user, 'password' => $pass));
$sessionid = $auth['auth']['sessionid'];
// Call prepareUpload to retrieve the token and endpoint we need to use
$prepare_resp = $v->viddler_videos_prepareUpload(array('sessionid' => $sessionid));
$upload_server = $prepare_resp['upload']['endpoint'];
$upload_token = $prepare_resp['upload']['token'];
?>
<form method="post" action="<?= $upload_server ?>" enctype="multipart/form-data">
<input type="hidden" name="uploadtoken" value="<?= $upload_token ?>" />
<input type="hidden" name="callback" value="<?= $callback_url ?>" />
<label>Title:</label> <input type="text" name="title" /><br />
<label>Description:</label> <input type="text" name="description" /><br />
<label>Tags:</label> <input type="text" name="tags" /><br />
<label>File:</label> <input type="file" name="file" /><br />
<input type="submit" value="Upload" />
</form>
You’ll see that I’ve also included a “callback” hidden field. This is a URL on your server that we’ll redirect to after the upload is finished. When we redirect, the video_id of the uploaded video will be included in the query string.
Hopefully this makes the experience of uploading videos to Viddler a little bit easier!
Subscribe
Viddler