Todos os produtos
Search
Central de documentação

ApsaraVideo Media Processing:Adicionar um arquivo de mídia

Última atualização: Jun 27, 2026

Após adicionar um arquivo de mídia à biblioteca de mídia do ApsaraVideo Media Processing (MPS), especifique o ID de um workflow para processar esse arquivo. Este tópico apresenta um exemplo de uso do MPS SDK for Java V2.0 para adicionar um arquivo de mídia à biblioteca e acionar um workflow específico para processá-lo.

Nota

Se o diretório do arquivo de mídia atender às regras de acionamento, o workflow será acionado. Caso contrário, o acionamento não ocorrerá. Para mais informações, consulte Regras de acionamento de workflow para arquivos.

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);
        }
    }
}