All Products
Search
Document Center

CDN

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Preload content to cache nodes

For more information about the request and response parameters, see PreloadVodObjectCaches.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("PreloadVodObjectCaches", {
    ObjectPath: 'http://testxxxx.testvodxxxxx.com/video/xxxxxxxx-1688e7fd1ca-0005-36ec-adb-xxxxx.mp4' // Sets the URL of the content to be preloaded.
}, {}).then(function (response) {
    // The ID of the preload task.
    console.log('PreloadTaskId = ' + response.PreloadTaskId);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Refresh the cached content on nodes

For more information about the request and response parameters, see RefreshVodObjectCaches.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("RefreshVodObjectCaches", {
    ObjectPath: 'http://testxxxx.testvodxxxxx.com/video/xxxxxxxx-1688e7fd1ca-0005-36ec-adb-xxxxx.mp4', // Sets the URL of the content to be refreshed.
    ObjectType: 'File' // Sets the type of the content to be refreshed.
}, {}).then(function (response) {
    // The ID of the refresh task.
    console.log('RefreshTaskId = ' + response.RefreshTaskId);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query the status of refresh and preload tasks

For more information about the request and response parameters, see DescribeVodRefreshTasks.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DescribeVodRefreshTasks", {
    DomainName: 'testxxxx.testvodxxxxx.com', // Specifies the domain name to be queried.
    ObjectType: 'File' // Sets the task type.
}, {}).then(function (response) {
    console.log(response);
    // The number of data records per page.
    console.log('PageSize = ' + response.PageSize);
    // The page number.
    console.log('PageNumber = ' + response.PageNumber);
    // The total number of data records.
    console.log('TotalCount = ' + response.TotalCount);
    // The task information.
    if (response.Tasks && response.Tasks.Task && response.Tasks.Task.length > 0){ 
        for (var i=0; i<response.Tasks.Task.length; i++){ 
            console.log('The ' + i + ' Task.');
            var task = response.Tasks.Task[i];
            // The task ID.
            console.log('TaskId = ' + task.TaskId);
            // The URL of the content to be refreshed or preloaded.
            console.log('ObjectPath = ' + task.ObjectPath);
            // The task status.
            console.log('Status = ' + task.Status);
            // The task progress, in percentage.
            console.log('Process = ' + task.Process);
            // The task type.
            console.log('ObjectType = ' + task.ObjectType);
            // The creation time of the task, in UTC.
            console.log('CreationTime = ' + task.CreationTime);
            // The error message returned when the refresh or preload task failed.
            console.log('Description = ' + task.Description);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Query the maximum number and remaining number of requests to refresh and preload content on the current day

For more information about the request and response parameters, see DescribeVodRefreshQuota.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DescribeVodRefreshQuota", {}, {}).then(function (response) {
    // The maximum number of requests to refresh URLs on the current day.
    console.log('UrlQuota = ' + response.UrlQuota);
    // The maximum number of requests to refresh directories on the current day.
    console.log('DirQuota = ' + response.DirQuota);
    // The remaining number of requests to refresh URLs on the current day.
    console.log('UrlRemain = ' + response.UrlRemain);
    // The remaining number of requests to refresh directories on the current day.
    console.log('DirRemain = ' + response.DirRemain);
    // The maximum number of requests to preload content on the current day.
    console.log('PreloadQuota = ' + response.PreloadQuota);
    // The remaining number of requests to preload content on the current day.
    console.log('PreloadRemain = ' + response.PreloadRemain);
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Obtain the network traffic monitoring data for accelerating domain names

For more information about the request and response parameters, see DescribeVodDomainTrafficData.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DescribeVodDomainTrafficData", {
    DomainName: 'testxxxx.testvodxxxxx.com', // Specifies the domain name to be queried.
    StartTime: '2019-01-15T15:59:59Z', // Sets the start time of queried data, in UTC.
    EndTime: '2019-01-20T15:59:59Z' // Sets the end time of queried data, in UTC.
}, {}).then(function (response) {
    // The accelerating domain name.
    console.log('DomainName = ' + response.DomainName);
    // The start time of queried data.
    console.log('StartTime = ' + response.StartTime);
    // The end time of queried data.
    console.log('EndTime = ' + response.EndTime);
    // The time interval of queried data.
    console.log('DataInterval = ' + response.DataInterval);
    // The network traffic data that is collected during each interval.
    if (response.TrafficDataPerInterval && response.TrafficDataPerInterval.DataModule && response.TrafficDataPerInterval.DataModule.length > 0){
        for(var i=0; i<response.TrafficDataPerInterval.DataModule.length; i++){ 
            var trafficData = response.TrafficDataPerInterval.DataModule[i];
            console.log("The " + i + " TrafficData.");
            console.log('TimeStamp = ' + trafficData.TimeStamp);
            console.log('Value = ' + trafficData.Value);
            console.log('DomesticValue = ' + trafficData.DomesticValue);
            console.log('OverseasValue = ' + trafficData.OverseasValue);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Obtain the network bandwidth monitoring data for accelerating domain names

For more information about the request and response parameters, see DescribeVodDomainBpsData.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DescribeVodDomainBpsData", {
    DomainName: 'testxxxx.testvodxxxxx.com', // Specifies the domain name to be queried.
    StartTime: '2019-01-15T15:59:59Z', // Sets the start time of queried data, in UTC.
    EndTime: '2019-01-20T15:59:59Z' // Sets the end time of queried data, in UTC.
}, {}).then(function (response) {
    // The accelerating domain name.
    console.log('DomainName = ' + response.DomainName);
    // The start time of queried data.
    console.log('StartTime = ' + response.StartTime);
    // The end time of queried data.
    console.log('EndTime = ' + response.EndTime);
    // The time interval of queried data.
    console.log('DataInterval = ' + response.DataInterval);
    // The network bandwidth data that is collected during each interval.
    if (response.BpsDataPerInterval && response.BpsDataPerInterval.DataModule && response.BpsDataPerInterval.DataModule.length > 0){ 
        for(var i=0; i<response.BpsDataPerInterval.DataModule.length; i++){
            var bpsData = response.BpsDataPerInterval.DataModule[i];
            console.log("The " + i + " BpsData.");
            console.log('TimeStamp = ' + bpsData.TimeStamp);
            console.log('Value = ' + bpsData.Value);
            console.log('DomesticValue = ' + bpsData.DomesticValue);
            console.log('OverseasValue = ' + bpsData.OverseasValue);
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});

Download raw CDN access logs for a specified domain name

For more information about the request and response parameters, see DescribeVodDomainLog.

// Call example
var client = initVodClient('<Your AccessKey ID>','<Your AccessKey Secret>');

client.request("DescribeVodDomainLog", {
    DomainName: 'testxxxx.testvodxxxxx.com', // Specifies the domain name to be queried.
    // PageSize: 300, // Sets the number of data records per page.
    // PageNumber: 1, // Sets the page number.
    StartTime: '2019-01-15T15:59:59Z', // Sets the start time of queried logs, in UTC.
    EndTime: '2019-01-20T15:59:59Z' // Sets the end time of queried logs, in UTC.
}, {}).then(function (response) {
    // The details about CDN logs.
    console.log(response.DomainLogDetails);
    if (response.DomainLogDetails && response.DomainLogDetails.DomainLogDetail && response.DomainLogDetails.DomainLogDetail.length > 0){ 
        for(var i=0; i<response.DomainLogDetails.DomainLogDetail.length; i++){ 
            var logData = response.DomainLogDetails.DomainLogDetail[i];
            console.log("The " + i + " LogData.");
            console.log('DomainName = ' + logData.DomainName);
            console.log('LogCount = ' + logData.LogCount);
            console.log('=== PageInfoDetail Data ===');
            console.log('PageNumber = ' + logData.PageInfos.PageNumber);
            console.log('PageSize = ' + logData.PageInfos.PageSize);
            console.log('Total = ' + logData.PageInfos.Total);
            console.log('=== LogInfoDetail Data ===');
            if (logData.LogInfos && logData.LogInfos.LogInfoDetail && logData.LogInfos.LogInfoDetail.length > 0){
                for (var j=0; j<logData.LogInfos.LogInfoDetail.length; j++){ 
                    var logInfoDetail = logData.LogInfos.LogInfoDetail[j]
                    console.log('LogName = ' + logInfoDetail.LogName);
                    console.log('LogPath = ' + logInfoDetail.LogPath);
                    console.log('LogSize = ' + logInfoDetail.LogSize);
                    console.log('StartTime = ' + logInfoDetail.StartTime);
                    console.log('EndTime = ' + logInfoDetail.EndTime);
                }
            }
        }
    }
    console.log('RequestId = ' + response.RequestId);
}).catch(function (response) {
    console.log('ErrorCode = ' + response.data.Code);
    console.log('ErrorMessage = ' + response.data.Message);
    console.log('RequestId = ' + response.data.RequestId);
});