Publishers

API for Publishers

 

Gateway

Our HTTP+JSON API is accessible from the Portal at /api/rpc. Contact support if you require any assistance.

Most up-to-date languages have HTTP and JSON modules or libraries, which allows you to easily interact with our services.

 

References

The quickest way to find out what are the supported methods is through the system.listMethods introspection from commonly implemented by many XML-RPC clients and servers. For HTTP+JSON, send your request to /api/rpc?v=2&s=system&m=listMethods&no_auth.

For further explanations on the API, please contact support for the API Reference Documentation.

 

Usage

Parameters

The supported GET parameters are as followed:

  • v - The API major version number. As of writing, the value is 2. It must always be provided to the server.
  • s - The service name, e.g. resource.
  • m - The method name, e.g. get.
  • a - The arguments in JSON format, e.g. ['username', 'secret', ...].
  • noauth - Use this if authentication is not required, e.g. during introspection.

Note that, if POST is used (usually for the reason of security and data size), arguments must be provided as the request content.

 

Authentication

Except methods of system namespace, all methods require a username and API key (generated through the Portal) for identification and authentication purposes. For better credential control, we do not recommend you to share the same key for all API clients.

The first two parameters of a method are mandatory and meant for your credentials, e.g. ?v=2&s=surrogate&m=get&a=['username', 'secret', ...]. Your username is your email registered with our system (unless you customized it), contact support otherwise if it does not work.

 

Examples

Examples in PHP

Retreiving a list of validating Resources

$url = "{$host}/api/rpc";
$url .= '?v=2&s=resource&m=get&a='; $url .= '["your@email.com/31337","foobar",{"status":"VALIDATING"}]'; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $o = curl_exec($c); curl_close($c); if($o){ $resources = json_decode($o); // ... }

 

Embedding Videos

This page allows you to play the video instantly using FlowPlayer and you may copy the embedded code to paste in on your website.

You may also change the width or edit the code and play the video again.

Embedded URL Video List

This page allows you to see all the video files that you have uploaded to the DFS Origin. Please wait 15 minutes to wait files to be reflected.

Beside, you may click "embed video" to play the video on the portal.

Concurrent Streaming Viewers

This page shows the concurrent viewers report for your CDN streamng sites.

Prefetch URL

This feature is to allow files pushed to all edge servers for CDN Pull site before first user request. It will be helpful for popular files or large files.

By selecting your desired CDN site and fill in the file paths on the text box.  System will request to cache the files on all the edge servers.

Java URI Hash Link Generation Sample

Sample code to generate the URI hash link using the Java programming language...

 

import java.util.Date;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

public static void main(String[] args) {
    long expires = new Date().getTime(); // get unix date

    String url = "http://yourUrl.com";
    String secretKey = "yourSecretKey";
    String rawKey = "rawKey";
    String originalValue = "originalValue";

    String keyStr = url + secretKey;
    // enabled if using expiry.
    // keyStr = expires+url+secretKey;
    try {
        SecretKeySpec key = new SecretKeySpec(rawKey.getBytes(), "Blowfish");
        Cipher cipher = Cipher.getInstance("Blowfish");
        cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
        cipher.doFinal(originalValue.getBytes());

        String hashKey = new String(Base64.encodeBase64(DigestUtils.md5(keyStr))).replace("+", "-").replace("\\", "_");

        System.out.println("Key: " + keyStr + "\nHash: " + hashKey);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

 

C# URI Hash Link Generation Sample Script

 

Sample script to generate the URI hash link using the C# programming language...

using System;
using System.Security.Cryptography;
using System.Text;

MD5 md5Hasher = MD5.Create();
byte[] hash;
string keyStr;
string base64;
double timestamp;

# Inputs from user
string secret; # secret key
string uri; # request uri , example /images/dotnet.jpg
DateTime date; # expiry datetime

keyStr = uri + secret;  
hash = md5Hasher.ComputeHash(Encoding.Default.GetBytes(keyStr));
base64 = Convert.ToBase64String(hash).Replace("+" , "-").Replace("/" , "_");
Console.WriteLine("Without timestamp");
Console.WriteLine("uri=" + uri + " ; keystr=" + keyStr + " ; urlHash=" + base64);

timestamp = Math.Round((date - new DateTime(1970,1,1,0,0,0)).TotalSeconds, 0);
keyStr = timestamp.ToString() + uri + secret;
hash = md5Hasher.ComputeHash(Encoding.Default.GetBytes(keyStr));
base64 = Convert.ToBase64String(hash).Replace("+" , "-").Replace("/" , "_");
Console.WriteLine("\nWith Timestamp for "  + date.ToString("u") + " , " + timestamp);
Console.WriteLine("uri=" + uri + " ; keystr=" + keyStr + " ; urlHash=" + base64);

 

Python URI Hash Link Generation Sample Script

Sample script to generate the hash URI using the Python programming language...

 

# import md5 # for python <2.5
import hashlib
import string
import base64
import time

secret_key = 'my_secret_key'
expires_y = 2010;
expires_m = 12;
expires_d = 11;
expires_H = 0;
expires_M = 0;
expires_S = 0;
expires = str(int(time.mktime(time.strptime("%d-%d-%d %d:%d:%d" % (expires_y , expires_m , expires_d , expires_H , expires_M , expires_S) , '%Y-%m-%d %H:%M:%S'))))

def get_hashkey(url , secret_key , expires=''):
   keystr = "%s%s%s" % (expires , url , secret_key)
   #hash_key = md5.new() # for python < 2.5
   hash_key = hashlib.md5()
   hash_key.update(keystr)
   base64_hash_key = base64.encodestring(hash_key.digest()).rstrip('\n').replace('+' , '-').replace('/' , '_')
   return base64_hash_key

# main prog:
print "No Expires %s “ % (get_hashkey(url , secret_key))
print "With Expires :  %s “ % (get_hashkey(url , secret_key , expires))

 

PHP CDN Site Hash Generation Script

Example script in PHP to generate the URI hash...

 

# unixdate generation sample:
$expires_y = '2010';
$expires_m = '12';
$expires_d = '11';
$expires = mktime(0 , 0 , 0 , $expires_m , $expires_d , $expires_y); 
# this therefore expires at 2010 Dec 11th, at 00:00:00

$arr_str_from   = array("+" , "/");
$arr_str_to     = array("-" , "_");
$keystr = "$url$secret_key";
# or $keystr = "$expires$url$secret_key"; # if using expiry. note that $expires is unixdate
$hashkey = str_replace($arr_str_from , $arr_str_to , base64_encode(md5($keystr , TRUE)));

 

Generating Hash Link

Take note that you may access to this page after URL singing is enabled during the adding/editing of this CDN site and it located via the "generate hash link" link in the respective CDN site listing page.

It enables the generation of the secret key to the resource under this CDN site.

First, enter the direct path to the file, and optionally select an expiry date and time. If this selection is earlier than today, it is invalid.

Finally clicking Generate Hash URL will cause the page to refresh with the generated URI (Uniform Resource Indicator) displayed. It is recommended that this URI is tested to ensure it is working.

If the URI is not working, contact the support team or site of the Operator.

Below are example programming scripts to generate hash link for all your files.

Syndicate content