本文提供了Node.js SDK新增视频文件到媒体库并触发工作流执行的完整代码示例。

示例代码

说明 如果上传的目录满足工作流触发条件,则会触发工作流执行,否则不触发。更多信息,请参见媒体工作流的文件触发匹配规则
var RPCClient = require('@alicloud/pop-core').RPCClient;

function initMtsClient(accessKeyId, accessKeySecret, regionId) {
    var client = new RPCClient({
        accessKeyId: accessKeyId,
        accessKeySecret: accessKeySecret,
        endpoint: 'http://mts.' + regionId + '.aliyuncs.com',
        apiVersion: '2014-06-18'
    });
    return client;
}

//Step 1 .set region:cn-hangzhou、cn-shenzhen、cn-shanghai、cn-beijing
var REGION = "xxx";
var OSS_REGION = "xxx";
var mtsEndpoint = "mts." + REGION + ".aliyuncs.com";

//Step 2.set accesskey & keySecret
var accessKeyId = "xxx";
var accessKeySecret = "xxx";

client = initMtsClient(accessKeyId, accessKeySecret, REGION)

client.request('AddMedia', {
  //FileURL示例:http://example-bucket-****.oss-cn-beijing.aliyuncs.com/music****.mp4
    FileURL: '<your FileURL>'

}, {}).then(function (response) {
    console.log(JSON.stringify(response));
}).catch(function (response) {
    console.log(response.requestId);
    console.log(response.Code);
});