Add a media file

更新时间:
复制 MD 格式

After you add a media file to the media library of ApsaraVideo Media Processing (MPS), you can specify the ID of a workflow to process the media file. This topic provides an example on how to use MPS SDK for Node.js V2.0 to add a media file to the media library and trigger a workflow to process the media file.

Sample code

Note

If the directory of the media file that you want to add meets the triggering rules of a workflow, the workflow is triggered. Otherwise, the workflow is not triggered. For more information, see Workflow triggering rules for files.

'use strict';


const Mts20140618 = require('@alicloud/mts20140618');
const OpenApi = require('@alicloud/openapi-client');
const Util = require('@alicloud/tea-util');
const Tea = require('@alicloud/tea-typescript');

class Client {

    /**
     * Use your AccessKey ID and AccessKey secret to initialize a client.
     * @return Client
     * @throws Exception
     */
    static createClient() {

        let config = new OpenApi.Config({
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                accessKeyId: process.env['ALIBABA_CLOUD_ACCESS_KEY_ID'],
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                accessKeySecret: process.env['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
    });

        config.endpoint = `mts.cn-qingdao.aliyuncs.com`;
        return new Mts20140618.default(config);
    }

    static async main(args) {
        let client = Client.createClient();
        let addMediaRequest = new Mts20140618.AddMediaRequest({
                // The path of the input file.
                fileURL: 'http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test.mp4',
                // The media title.
                title: 'mytest',
                // The description.
                description: 'A test video',
                // The URL of the media thumbnail.
                coverURL: 'http://bucket.oss-cn-hangzhou.aliyuncs.com/example/1.png',
                // The tags.
                tags: 'tag1,tag2',
                // The ID of the media workflow.
                mediaWorkflowId: '07da6c65da7f458997336e0de192****',
                // The custom data of the media workflow.
                mediaWorkflowUserData: 'test',
                // Specify whether to check if the media workflow supports the specified input path.
                inputUnbind: false,
                // The ID of the category to which the media file belongs.
                cateId: 123,
                // Set the overrideParams parameter.
                overrideParams: '{“subtitleTransNodeName”:{“InputConfig”:{“Format”:”stl”,”InputFile”:{“URL”:”http://exampleBucket.oss-cn-hangzhou.aliyuncs.com/package/example/CENG.stl"}}}}',
    });
        let runtime = new Util.RuntimeOptions({ });
        try {
            // Write your own code to display the response of the API operation if necessary.
            await client.addMediaWithOptions(addMediaRequest, runtime);
        } catch (error) {
            // Handle exceptions with caution in actual business scenarios and never ignore exceptions in your project. In this example, error messages are displayed for reference only. 
            // The error message.
            console.log(error.message);
            // The URL of the corresponding error diagnostics page.
            console.log(error.data["Recommend"]);
            Util.default.assertAsString(error.message);
        }
    }

}

exports.Client = Client;
Client.main(process.argv.slice(2));