All Products
Search
Document Center

ApsaraVideo VOD:Media upload

Last Updated:Jan 08, 2024

ApsaraVideo VOD server operation SDK provides various API operations for media upload. You can call the API operations to upload media files to ApsaraVideo VOD. This topic describes the scenarios in which you can use the server operation SDK for Java to call API operations to upload media files and provides sample code.

Scenarios

Important

This topic provides only the examples of calling API operations, such as the operation for obtaining an upload credential and an upload URL. The following table describes the scenarios in which API operations can be called to upload media files.

API operation

Scenario

CreateUploadVideo

  • If you upload media files by using Object Storage Service (OSS) SDKs, you must use the server operation SDK and call an operation to obtain an upload credential and an upload URL. The obtained URL and credential are Base64-encoded and must be decoded before they are used to initialize an OSSClient instance. For more information, see Upload media files by using OSS SDKs. The preceding topic provides complete sample code for uploading media files by using OSS SDK for Java. For more information about the sample code in other languages, see Upload media files by calling the ApsaraVideo VOD API.

  • If you upload media files from clients by using the upload SDK, you need to integrate the server operation SDK and call an operation to obtain or update an upload credential and an upload URL. You can issue URLs and credentials to clients without the need to decode them. For more information, see Client upload SDKs.

RefreshUploadVideo

CreateUploadImage

CreateUploadAttachedMedia

UploadMediaByURL

  • You can call the UploadMediaByURL operation to upload media files by using the URLs of source files. This way, you do not need to download media files to your servers or devices before you use the upload SDK to upload the media files to ApsaraVideo VOD.

    Note

    The URL-based upload jobs are asynchronous. After you submit a URL-based upload job, it may take hours, even days to complete.

  • You can call the GetURLUploadInfos operation to query the progress of URL-based upload jobs.

GetURLUploadInfos

RegisterMedia

  • After you add your OSS bucket to ApsaraVideo VOD and upload media files to the bucket, you can call the RegisterMedia operation to obtain the file IDs. After you register the media files, you can submit transcoding or snapshot jobs for the media files. For more information, see Add a user-created OSS bucket.

Prerequisites

  • The ApsaraVideo VOD SDK for Java is installed. For more information, see Installation.

  • The ApsaraVideo VOD SDK for Java is initialized. For more information, see Initialization.

Usage notes

  • In this example, an AccessKey pair is used to initialize a client instance.

  • For more information about the request and response parameters of this operation, visit OpenAPI Explorer. You can click API Documentations in the top navigation bar to view information related to the API operation.

  • This topic provides sample code only for some complex API operations. To obtain sample code for other API operations, perform the following operations: Visit Alibaba Cloud OpenAPI Explorer. In the left-side navigation pane, find the API operation whose sample code you want to obtain and specify the required parameters on the Parameters tab. Then, click Initiate Call. On the SDK Sample Code tab, select the language to view and download the sample code.

  • This topic describes how to use the ApsaraVideo VOD SDK for Java V1.0 to call API operations. If you use the ApsaraVideo VOD SDK for Java V2.0 to call API operations, specify V2.0 when you obtain the sample code on Alibaba Cloud OpenAPI Explorer.image.png

API call examples

Obtain a URL and a credential for uploading an audio or video file

You can call the CreateUploadVideo operation to obtain an upload URL and an upload credential for uploading an audio or video file.

Click CreateUploadVideo to learn more about this operation.

Sample code:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;

/**
 *
 * Sample code for obtaining a credential for uploading an audio or video file
 */
public class AudioOrVideoCreateUploadDemo {

    /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Obtain an upload URL and an upload credential for uploading an audio or video file.
     * @param client The client that sends a request.
     * @return CreateUploadVideoResponse The fields contained in the response.
     * @throws Exception
     */
    public static CreateUploadVideoResponse createUploadVideo(DefaultAcsClient client) throws Exception {
        CreateUploadVideoRequest request = new CreateUploadVideoRequest();
        request.setTitle("this is a sample");
        request.setFileName("filename.mp4");

        // Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
        //JSONObject userData = new JSONObject();

        // The callback configurations in the user data.
        // The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
        //JSONObject messageCallback = new JSONObject();
        // The callback URL.
        //messageCallback.put("CallbackURL", "http://192.168.0.1/16");
        // The callback type. Default value: http.
        //messageCallback.put("CallbackType", "http");
        //userData.put("MessageCallback", messageCallback.toJSONString());

        // The configurations of transparent data transmission in the user data.
        // The user-defined extension parameter, which is transparently transferred during the callback.
        //JSONObject extend = new JSONObject();
        //extend.put("MyId", "user-defined-id");
        //userData.put("Extend", extend.toJSONString());

        //request.setUserData(userData.toJSONString());

        return client.getAcsResponse(request);
    }
  
    /** 
     * Request example
     */
    public static void main(String[] argv) throws ClientException {
        try {
            DefaultAcsClient client = initVodClient();
            CreateUploadVideoResponse response = new CreateUploadVideoResponse();
            response = createUploadVideo(client);
            System.out.print("VideoId = " + response.getVideoId() + "\n");
            System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
            System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }
}

Update the credential for uploading an audio or video file

You can call the RefreshUploadVideo operation to update the credential for uploading an audio or video file.

Click RefreshUploadVideo to learn more about this operation.

Sample code:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoRequest;
import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse;

/**
*
* Sample code for updating the credential for uploading an audio or video file
*/
public class AudioOrVideoRefreshUploadDemo {

    /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Update the credential for uploading an audio or video file.
     * @param client The client that sends a request.
     * @return RefreshUploadVideoResponse The fields contained in the response.
     * @throws Exception
     */
    public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient client) throws Exception {
        RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
        // The ID of the audio file or video.
        request.setVideoId("<VideoId>");
        return client.getAcsResponse(request);
    }

    /** 
     * Request example
     */
    public static void main(String[] argv)  {

        try {
            DefaultAcsClient client = initVodClient();
            RefreshUploadVideoResponse response = refreshUploadVideo(client);
            System.out.print("VideoId = " + response.getVideoId() + "\n");
            System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
            System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }
}

Obtain a URL and a credential for uploading an image

You can call the CreateUploadImage operation to obtain a URL and a credential for uploading an image.

Click CreateUploadImage to learn more about this operation.

Sample code:

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadImageRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadImageResponse;

/**
 * Sample code for obtaining a URL and a credential for uploading an image.
 *
 */
public class ImageCreateUploadDemo {

    /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Obtain a URL and a credential for uploading an image.
     * @param client The client that sends a request.
     * @return CreateUploadImageResponse The fields contained in the response.
     * @throws Exception
     */
    public static CreateUploadImageResponse createUploadImage(DefaultAcsClient client) throws Exception {
        CreateUploadImageRequest request = new CreateUploadImageRequest();
        // The image type.
        request.setImageType("default");
        // The file name extension of the image.
        request.setImageExt("gif");
        // The image title.
        request.setTitle("this is a sample");

        // Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
        JSONObject userData = new JSONObject();

        // The callback configurations in the user data.
        // The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
        JSONObject messageCallback = new JSONObject();
        // The callback URL.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // The callback type. Default value: http.
        messageCallback.put("CallbackType", "http");
        userData.put("MessageCallback", messageCallback.toJSONString());

        JSONObject extend = new JSONObject();
        extend.put("MyId", "user-defined-id");
        userData.put("Extend", extend.toJSONString());

        request.setUserData(userData.toJSONString());

        return client.getAcsResponse(request);
    }

    /** 
     * Request example
     */
    public static void main(String[] argv)  {

        try {
            DefaultAcsClient client = initVodClient();
            CreateUploadImageResponse response = createUploadImage(client);
            System.out.print("ImageId = " + response.getImageId() + "\n");
            System.out.print("ImageURL = " + response.getImageURL() + "\n");
            System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
            System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }
}

Obtain a URL and a credential for uploading an auxiliary media asset

You can call the CreateUploadAttachedMedia operation to obtain a URL and a credential for uploading an auxiliary media asset.

Click CreateUploadAttachedMedia to learn more about this operation.

Sample code:

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.CreateUploadAttachedMediaRequest;
import com.aliyuncs.vod.model.v20170321.CreateUploadAttachedMediaResponse;

/**
 * Sample code for obtaining a URL and a credential for uploading an auxiliary media asset
 *
 */
public class AttachedMediaCreateUploadDemo {

     /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Obtain a URL and a credential for uploading an auxiliary media asset, such as a watermark or subtitle file.
     * @param client The client that sends a request.
     * @return CreateUploadAttachedMediaResponse The fields contained in the response.
     * @throws Exception
     */
    public static CreateUploadAttachedMediaResponse createUploadAttachedMedia(DefaultAcsClient client) throws Exception {
        CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
        // The business type.
        request.setBusinessType("watermark");
        // The file name extension.
        request.setMediaExt("gif");
        // The title.
        request.setTitle("this is a sample");

        // Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
        JSONObject userData = new JSONObject();

        // The callback configurations in the user data.
        // The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
        JSONObject messageCallback = new JSONObject();
        // The callback URL.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // The callback type. Default value: http.
        messageCallback.put("CallbackType", "http");
        userData.put("MessageCallback", messageCallback.toJSONString());

        JSONObject extend = new JSONObject();
        extend.put("MyId", "user-defined-id");
        userData.put("Extend", extend.toJSONString());

        request.setUserData(userData.toJSONString());

        return client.getAcsResponse(request);
    }
    /** 
     * Request example
     */
    public static void main(String[] argv) {

        try {
            DefaultAcsClient client = initVodClient();
            CreateUploadAttachedMediaResponse response = createUploadAttachedMedia(client);
            System.out.print("mediaId = " + response.getMediaId() + "\n");
            System.out.print("mediaURL = " + response.getMediaURL() + "\n");
            System.out.print("UploadAddress = " + response.getUploadAddress() + "\n");
            System.out.print("UploadAuth = " + response.getUploadAuth() + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }
}

Upload multiple media files at a time based on URLs

You can call the UploadMediaByURL operation to upload multiple media files at a time based on URLs.

Click UploadMediaByURL to learn more about this operation.

Sample code:

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLRequest;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLResponse;

import java.net.URLEncoder;

/**
 * Sample code for uploading media files at a time based on URLs
 *
 */
public class AudioOrVideoUploadByUrl {

    /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai"; 
    // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Upload media files at a time based on URLs.
     *
     * @param client The client that sends a request.
     * @return UploadMediaByURLResponse The fields contained in the response.
     * @throws Exception
     */
    public static UploadMediaByURLResponse uploadMediaByURL(DefaultAcsClient client) throws Exception {
        UploadMediaByURLRequest request = new UploadMediaByURLRequest();
        String url = "http://video_01.mp4";
        String encodeUrl = URLEncoder.encode(url, "UTF-8");
        // The URLs of source files.
        request.setUploadURLs(encodeUrl);

        // The metadata of the video that you want to upload.
        JSONObject uploadMetadata = new JSONObject();
        // The URLs of the source files that you want to upload. The URL must be included in the value of the UploadURLs parameter.
        uploadMetadata.put("SourceUrl", encodeUrl);
        // The video title.
        uploadMetadata.put("Title", "upload by url sample");

        JSONArray uploadMetadataList = new JSONArray();
        uploadMetadataList.add(uploadMetadata);
        request.setUploadMetadatas(uploadMetadataList.toJSONString());

        // Optional. The user data that consists of user-defined parameters. Configure the user data if you need a callback URL and transparent data transmission.
        JSONObject userData = new JSONObject();

        // The callback configurations in the user data.
        // The callback settings for event notifications. If you specify callback settings, the specified callback settings take effect. Otherwise, the global callback settings take effect.
        JSONObject messageCallback = new JSONObject();
        // The callback URL.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // The callback type. Default value: http.
        messageCallback.put("CallbackType", "http");
        userData.put("MessageCallback", messageCallback.toJSONString());

        JSONObject extend = new JSONObject();
        extend.put("MyId", "user-defined-id");
        userData.put("Extend", extend.toJSONString());

        request.setUserData(userData.toJSONString());

        return client.getAcsResponse(request);
    }

    /** 
     * Request example
     */
    public static void main(String[] argv) {

        try {
            DefaultAcsClient client = initVodClient();
            UploadMediaByURLResponse response = uploadMediaByURL(client);
            System.out.print("UploadJobs = " + JSON.toJSONString(response.getUploadJobs()) + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }

}

Register media assets

You can call the RegisterMedia operation to register media assets.

Click RegisterMedia to learn more about this operation.

Sample code:

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.RegisterMediaRequest;
import com.aliyuncs.vod.model.v20170321.RegisterMediaResponse;

/**
 * Sample code for registering media assets
 *
 */
public class MediaRegisterDemo {

    /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Register media assets.
     * @param client The client that sends a request.
     * @return RegisterMediaResponse The fields contained in the response.
     * @throws Exception
     */
    public static RegisterMediaResponse registerMedia(DefaultAcsClient client) throws Exception {
        RegisterMediaRequest request = new RegisterMediaRequest();
        JSONArray metaDataArray = new JSONArray();
        JSONObject metaData = new JSONObject();
        // The title.
        metaData.put("Title", "this is a sample");
        // The URL of the source file. The file name in the URL must be unique. If the file name is repeatedly registered, the unique media ID that is associated with the file name is returned. 
        metaData.put("FileURL", "https://192.168.0.0/16.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4");
        // The metadata of the media asset to be registered.
        metaDataArray.add((metaData));
        request.setRegisterMetadatas(metaDataArray.toJSONString());
        return client.getAcsResponse(request);
    }

    /** 
     * Request example
     */
    public static void main(String[] argv)  {

        try {
            DefaultAcsClient client = initVodClient();
            RegisterMediaResponse response = registerMedia(client);
            if (response.getFailedFileURLs() != null && response.getFailedFileURLs().size() > 0) {
                for (String fileURL : response.getFailedFileURLs()) {
                    System.out.print("FailedFileURL = " + fileURL + "\n");
                }
            }
            if (response.getRegisteredMediaList() != null && response.getRegisteredMediaList().size() > 0) {
                for (RegisterMediaResponse.RegisteredMedia registeredMedia : response.getRegisteredMediaList()) {
                    System.out.print("MediaId = " + registeredMedia.getMediaId());
                    System.out.print("FileURL = " + registeredMedia.getFileURL());
                    System.out.print("NewRegister = " + registeredMedia.getNewRegister());
                    System.out.print("RequestId = " + response.getRequestId() + "\n");
                }
            }
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }

    }

}

Query the information about URL-based upload jobs

You can call the GetURLUploadInfos operation to query the information about URL-based upload jobs.

Click GetURLUploadInfos to learn more about this operation.

Sample code:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.AlibabaCloudCredentials;
import com.aliyuncs.auth.EnvironmentVariableCredentialsProvider;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetURLUploadInfosRequest;
import com.aliyuncs.vod.model.v20170321.GetURLUploadInfosResponse;
import org.apache.commons.lang3.StringUtils;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * Query the information about URL-based upload jobs.
 */
public class URLUploadInfosGetDemo {
    
    /** 
     * Obtain the AccessKey information.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The region in which ApsaraVideo VOD is activated.
    String regionId = "cn-shanghai";  
    // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. 
    // We recommend that you not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. 
    // In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. 
    DefaultProfile profile = DefaultProfile.getProfile(regionId, System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
    DefaultAcsClient client = new DefaultAcsClient(profile);
    return client;
    }

    /**
     * Query information about URL-based upload jobs.
     *
     * @param client The client that sends a request.
     * @return GetURLUploadInfosResponse The fields contained in the response.
     * @throws Exception
     */
    public static GetURLUploadInfosResponse getURLUploadInfos(DefaultAcsClient client) throws Exception {
        GetURLUploadInfosRequest request = new GetURLUploadInfosRequest();

        // The URLs of video source files. The URLs must be encoded.
        String[] urls = {
                "http://exampleBucket****.cn-shanghai.aliyuncs.com/video_01.mp4",
                "http://exampleBucket****.cn-shanghai.aliyuncs.com/video_02.flv"
        };
        List<String> encodeUrlList = new ArrayList<String>();
        for (String url : urls) {
            encodeUrlList.add(URLEncoder.encode(url, "UTF-8"));
        }
        request.setUploadURLs(StringUtils.join(encodeUrlList, ','));
        // The job IDs. You can obtain the job IDs from the PlayInfo parameter returned by the GetPlayInfo operation.
        //request.setJobIds("exampleID1,exampleID2");

        return client.getAcsResponse(request);
    }

    /** 
     * Request example
     */
    public static void main(String[] argv) {

        try {
            DefaultAcsClient client = initVodClient();
            GetURLUploadInfosResponse response = getURLUploadInfos(client);
            System.out.print("URLUploadInfoList = " + response.getURLUploadInfoList() + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
    }
}