Category Archives: PHP

PHP sample video upload from browser to VdoCipher

[This article is based on API v2 as document here.]

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.

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.

Video upload from website or server to vdocipher API

[The following article on video upload is based on vdocipher API v2 which is the latest version]

We use Amazon aws storage to store original user videos securely in AWS S3. With an intent to automate their online business, many of our customers wish to allow their users to upload videos directly from their website. To enable this, we have a API call that returns an authenticated policy document which is used video upload into a S3 bucket allotted to your account.

Step 1 (Obtain authorized access):

Create authorized video upload request with your API secret key.

Request
Endpoint: https://api.vdocipher.com/v2/uploadPolicy
Content type: application/x-www-form-urlencoded
Method: POST
PostData: clientSecretKey=API_SECRET_KEY&title=newTitle
Response
Content-Type: application/json

{
 policy:
 key:
 x-amz-signature: 
 x-amz-algorithm: ,
 x-amz-date:
 x-amz-credential: 
 policy:
 upload_link_secure:
 video_id:
}

The API call has returned a set of parameters that must go with the video upload call to the AWS S3 endpoint. We shall refer to this JSON object returned above as uploadData.

The policy document is valid only for the next 1 hour. It is recommended to make the video upload immediately after creating the authorized access. There is also a soft restriction on the number of upload calls every hour, so it is advised to create it only after the user has chosen to upload the video. It should not be made every time somebody loads their dashboard or mobile app.

This call must be made from a secure environment such as your server. This should not be called from a mobile device or the browser to protect your API key. The uploadData should then be passed to user’s device (mobile or browser) to do the file upload.

Step 2 (Video upload via S3 API):

Upload the file to amazon s3 directly. This upload can be made using server code or using an HTML5 form. You can use any third party upload library to make the upload script. The famous ones already have tutorials on setting it up with S3 upload.

application Request
Endpoint: https://{bucket}.s3.amazonaws.com/
Method: POST
PostData:
 'x-amz-credential': uploadData['x-amz-credential'],
 'x-amz-algorithm': uploadData['x-amz-algorithm'],
 'x-amz-date' : uploadData['x-amz-date'],
 'x-amz-signature': uploadData['x-amz-signature'],
 key : uploadData['key'],
 policy : uploadData['policy'],
 success_action_status : 201,
 success_action_redirect : 'http://example.com'
 file: <file content>
  • upload_link_secure string – The vdocipher storage location that has been allocated for this file
  • key string – A name for the S3 object that will store the uploaded file’s data
  • policy string – authorization string
  • x-amz-signature string – A signature value that authorizes the form and proves that only vdocipher could have created it.
  • x-amz-credential string – These must be accompanied in the upload request.
  • x-amz-algorithm string
  • x-amz-date string
  • success_action_status integer – The status code returned upon successful upload if success_action_redirect is not specified.
  • success_action_redirect string(optional) – Specifies if to redirect to a URL after a successful post instead of issuing a 201.

If everything goes right, the response from the above request should be:

Response
<?xml version="1.0" encoding="UTF-8"?>
<PostResponse>
  <Location>https://vdo-ap-southeast.s3.amazonaws.com/orig%2F5555555555555</Location>
  <Bucket>vdo-ap-southeast</Bucket><Key>orig/5555555555555</Key>
  <ETag>xxxxxxxxxxxxxxxxxx</ETag>
</PostResponse>

You can ignore the content of this response. Now, the video status should be shown as Queued or Processing in the API or on your dashboard. The video will get processed after some time. You can poll the API or configure the web hooks(coming soon) to know the time when video is ready. You should only load the video player if the video is ready.

 

Some sample code for the above operations:

PHP implementation of VdoCipher API

Here is a classic PHP code to use VdoCipher API along with dynamic watermarking. You need to simply put in the right client_secret_key and the correct video_id ( the phrase in caps in both files )

 

The code should work out of the box after extracting inside PHP running server and replacing secret_key and video_id.

The structure of annotation JSON is described in the link : Add text to videos with watermark