All Products
Search
Document Center

ApsaraVideo Media Processing:Add a media file

Last Updated:Nov 19, 2024

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 Java V2.0 to add a media file to the media library and trigger a specific workflow to process the media file.

Note

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

package com.aliyun.sample;

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>Use your AccessKey ID and AccessKey secret to initialize the client.</p>
     * @return Client
     *
     * @throws Exception
     */
    public static com.aliyun.mts20140618.Client createClient() throws Exception {

        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. 
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. 
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "mts.cn-qingdao.aliyuncs.com";
        return new com.aliyun.mts20140618.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.mts20140618.Client client = Sample.createClient();
        com.aliyun.mts20140618.models.AddMediaRequest addMediaRequest = new com.aliyun.mts20140618.models.AddMediaRequest()
                // The URL of the input file.
                .setFileURL("http://bucket.oss-cn-hangzhou.aliyuncs.com/A/B/C/test.mp4")
                // The media title.
                .setTitle("mytest")
                // The description.
                .setDescription("A test video")
                // The URL of the media thumbnail.
                .setCoverURL("http://bucket.oss-cn-hangzhou.aliyuncs.com/example/1.png")
                // The tags.
                .setTags("tag1,tag2")
                // The ID of the media workflow.
                .setMediaWorkflowId("07da6c65da7f458997336e0de192****")
                // The custom data of the media workflow.
                .setMediaWorkflowUserData("test")
                // Specify whether to check if the media workflow supports the specified input path.
                .setInputUnbind(false)
                // The ID of the category to which the media file belongs.
                .setCateId(123L)
                // Set the overrideParams parameter.
                .setOverrideParams("{“subtitleTransNodeName”:{“InputConfig”:{“Format”:”stl”,”InputFile”:{“URL”:”http://exampleBucket.oss-cn-hangzhou.aliyuncs.com/package/example/CENG.stl\"}}}}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // Write your own code to display the response of the API operation if necessary.
            client.addMediaWithOptions(addMediaRequest, runtime);
        } catch (TeaException 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.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _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.
            System.out.println(error.getMessage());
            // The URL of the corresponding error diagnostics page.
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}