The Upload API workflow and overview can be found here.
Please find below a sample code for enabling video upload from your PHP website’s users. Note that this is sample code and you will need to configure it according to the controller-view structure in your application. It is not a recommended to put Controller logic and HTML output in a single file.
https://gist.github.com/vibhavsinha/71d394132a98c049f8aa
<?php
function send($action, $params, $posts = false){
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$getData = http_build_query($params);
$postData = ['clientSecretKey'=>'CLIENT_SECRET_KEY']; ////Replace the caps CLIENT_SECRET_KEY with your video id.
if ($posts) {
$postData = http_build_query(array_merge($postData, $posts));
}
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
$url = "http://api.vdocipher.com/v2/$action/?$getData";
curl_setopt($curl, CURLOPT_URL,$url);
$html = curl_exec($curl);
curl_close($curl);
return $html;
}
$upload_data = json_decode(send('uploadPolicy', [], ['title'=>'NEW_TITLE']), true);
if (is_null($upload_data)) {
throw new Exception('Exception: ' . $upload_data);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="<?= $upload_data['upload_link_secure'] ?>" method="post" enctype="multipart/form-data">
Key to upload:
<input type="hidden" name="key" value="<?= $upload_data['key'] ?>" /><br />
<input type="hidden" name="success_action_status" value="201" />
<input type="hidden" name="success_action_redirect" value="https://www.vdocipher.com" />
<input type="hidden" name="X-Amz-Credential" value="<?= $upload_data['x-amz-credential'] ?>" />
<input type="hidden" name="X-Amz-Algorithm" value="<?= $upload_data['x-amz-algorithm'] ?>" />
<input type="hidden" name="X-Amz-Date" value="<?= $upload_data['x-amz-date'] ?>" />
<input type="hidden" name="Policy" value='<?= $upload_data['policy'] ?>' />
<input type="hidden" name="X-Amz-Signature" value="<?= $upload_data['x-amz-signature'] ?>" />
File:
<input type="file" name="file" /> <br />
<!-- The elements after this will be ignored -->
<input type="submit" name="submit" value="Upload to Amazon S3" />
</form>
</html>
When setting up your front-end, you will like to enable better interface with AJAX upload such that your user’s can have a seamless experience. For this it is recommended to use one of the available libraries(angularjs, jquery or standalone, etc.) . Note that all these can be modified to be used in this set up. You can also see a sample implementation of the angular’s ng-file-upload library in your vdocipher dashboard itself.
Supercharge Your Business with Videos
At VdoCipher we maintain the strongest content protection for videos. We also work extremely hard to deliver the best viewer experience. We'd love to hear from you, and help boost your video streaming business.
Leave a Reply