All Products
Document Center

ApsaraVideo Media Processing:Add a media file

Last Updated:Aug 28, 2023

This topic provides the sample code for using ApsaraVideo Media Processing (MPS) SDK for Java to add a video file to the media library. You can specify the ID of a workflow to process the video file.


If the directory of the video 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.

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.mts.model.v20140618.AddMediaRequest;
import com.aliyuncs.mts.model.v20140618.AddMediaResponse;

 * *****   Usage notes     ******
 * This sample code triggers a workflow to process an existing media file.
public class AddMedia {

    public static void main(String[] args) throws ClientException {

        DefaultAcsClient client = Config.initMpsClient();
        // Initiate an API request and handle the response or exception.
        AddMediaResponse response;
        try {
            response = addMedia(client);
            System.out.println("RequestId is:" + response.getRequestId());
            System.out.println("Media Info is:" + JSON.toJSON(response.getMedia()));
        } catch (Exception e) {

    public static AddMediaResponse addMedia(DefaultAcsClient client) throws Exception{
        // Create an API request and specify the request parameters.
        AddMediaRequest request = new AddMediaRequest();
        // The URL of the media file for which you want to trigger a workflow.
        request.setFileURL("http://<your bucket name>");
        request.setTitle("case title");
        // The ID of the workflow that you want to trigger. To obtain the ID of a workflow, log on to the MPS console and choose Workflow > Workflow Orchestration in the left-side navigation pane.
        return client.getAcsResponse(request);