Media upload

Updated at:
Copy as MD

ApsaraVideo VOD provides server-side upload APIs. This topic provides Java SDK sample code for obtaining upload credentials, refreshing credentials, and registering media assets.

Use cases and related APIs

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 ApsaraVideo VOD 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 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 ApsaraVideo VOD 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 Upload from clients.

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

Register media assets

Prerequisites

Usage notes

  • All examples in this topic use an AccessKey pair to initialize a client instance.

  • For request and response parameter details, visit Alibaba Cloud OpenAPI Explorer and open the API Documentations tab.

  • For SDK examples of other API operations, visit Alibaba Cloud OpenAPI Explorer. On the Parameters tab, specify the parameters and initiate the call. Then select the SDK version and language on the SDK Sample Code tab to view and download the code.

  • The examples in this topic use SDK V1.0. For V2.0 examples, select the correct SDK version in OpenAPI Explorer.image.png

API call examples

Get upload credentials for audio and video

Call CreateUploadVideo to obtain an upload URL and credential for an audio or video file.

Alibaba Cloud OpenAPI Explorer: CreateUploadVideo.

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;

/**
 *
 * Example of obtaining an upload credential for an audio or video file.
 */
public class AudioOrVideoCreateUploadDemo {

    /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai";  
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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;
    }

    /**
     * Get an upload URL and credential for an audio or video file.
     * @param client The client that sends the request.
     * @return CreateUploadVideoResponse The response that contains the upload URL and credential for an audio or video file.
     * @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. Set this parameter if you want to specify a callback URL and enable transparent data transmission.
        //JSONObject userData = new JSONObject();

        // Callback settings in UserData.
        // The callback settings for event notifications. If you specify these settings, they override the global event notification settings.
        //JSONObject messageCallback = new JSONObject();
        // Set the callback URL.
        //messageCallback.put("CallbackURL", "http://192.168.0.1/16");
        // Set the callback method. Default value: http.
        //messageCallback.put("CallbackType", "http");
        //userData.put("MessageCallback", messageCallback.toJSONString());

        // Transparent data transmission settings in UserData.
        // A custom-defined extended field that is returned in 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());
        }
    }
}

Refresh upload credentials for audio and video

Call RefreshUploadVideo to refresh an expired upload credential for an audio or video file.

Alibaba Cloud OpenAPI Explorer: RefreshUploadVideo.

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;

/**
*
* Example of refreshing an upload credential for an audio or video file.
*/
public class AudioOrVideoRefreshUploadDemo {

    /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai";  
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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;
    }

    /**
     * Refresh the upload credential for an audio or video file.
     * @param client The client that sends the request.
     * @return RefreshUploadVideoResponse The response that contains the refreshed upload credential for the audio or video file.
     * @throws Exception
     */
    public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient client) throws Exception {
        RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
        // The ID of the audio or video file.
        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());
        }
    }
}

Get upload credentials for an image

Call CreateUploadImage to obtain an upload URL and credential for an image.

Alibaba Cloud OpenAPI Explorer: CreateUploadImage.

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;

/**
 * Example of obtaining an upload credential for an image.
 *
 */
public class ImageCreateUploadDemo {

    /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai";  
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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;
    }

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

        // Optional. The user data. Set this parameter if you want to specify a callback URL and enable transparent data transmission.
        JSONObject userData = new JSONObject();

        // Callback settings in UserData.
        // The callback settings for event notifications. If you specify these settings, they override the global event notification settings.
        JSONObject messageCallback = new JSONObject();
        // Set the callback URL.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // Set the callback method. 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());
        }
    }
}

Get upload credentials for auxiliary media

Call CreateUploadAttachedMedia to obtain an upload URL and credential for an auxiliary media asset such as a watermark or subtitle file.

Alibaba Cloud OpenAPI Explorer: CreateUploadAttachedMedia.

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;

/**
 * Example of obtaining an upload credential for an auxiliary media asset.
 *
 */
public class AttachedMediaCreateUploadDemo {

     /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai";
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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;
    }

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

        // Optional. The user data. Set this parameter if you want to specify a callback URL and enable transparent data transmission.
        JSONObject userData = new JSONObject();

        // Callback settings in UserData.
        // The callback settings for event notifications. If you specify these settings, they override the global event notification settings.
        JSONObject messageCallback = new JSONObject();
        // Set the callback URL.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // Set the callback method. 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());
        }
    }
}

URL-based batch upload

Call UploadMediaByURL to upload media files by URL in batches.

Alibaba Cloud OpenAPI Explorer: UploadMediaByURL.

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;

/**
 * Example of the URL-based batch upload feature.
 *
 */
public class AudioOrVideoUploadByUrl {

    /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai"; 
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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;
    }

    /**
     * URL-based batch upload.
     *
     * @param client The client that sends the request.
     * @return UploadMediaByURLResponse The response of the URL-based batch upload operation.
     * @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 URL of the source video file.
        request.setUploadURLs(encodeUrl);

        // The metadata of the video to upload.
        JSONObject uploadMetadata = new JSONObject();
        // The URL of the source video file to upload. This must match a URL in 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. Set this parameter if you want to specify a callback URL and enable transparent data transmission.
        JSONObject userData = new JSONObject();

        // Callback settings in UserData.
        // The callback settings for event notifications. If you specify these settings, they override the global event notification settings.
        JSONObject messageCallback = new JSONObject();
        // Set the callback URL.
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        // Set the callback method. 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 a media asset

Call RegisterMedia to register media assets.

Alibaba Cloud OpenAPI Explorer: RegisterMedia.

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;

/**
 * Example of media asset registration.
 *
 */
public class MediaRegisterDemo {

    /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai";  
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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 a media asset.
     * @param client The client that sends the request.
     * @return RegisterMediaResponse The response of the media asset registration operation.
     * @throws Exception
     */
    public static RegisterMediaResponse registerMedia(DefaultAcsClient client) throws Exception {
        RegisterMediaRequest request = new RegisterMediaRequest();
        JSONArray metaDataArray = new JSONArray();
        JSONObject metaData = new JSONObject();
        // Title.
        metaData.put("Title", "this is a sample");
        // The URL of the source file. The filename must be unique. If you add a file with a name that already exists, the file is associated with the existing unique media ID.
        metaData.put("FileURL", "https://192.168.0.0/16.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4");
        // Specify the metadata of the media asset to register.
        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 URL upload information

Call GetURLUploadInfos to query the status and details of URL-based upload jobs.

Alibaba Cloud OpenAPI Explorer: GetURLUploadInfos.

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;

/**
 * Example of getting URL upload information.
 */
public class URLUploadInfosGetDemo {
    
    /** 
     * Initializes the AcsClient.
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // The service region for ApsaraVideo for VOD.
    String regionId = "cn-shanghai";  
    // An AccessKey of an Alibaba Cloud account has full permissions on all API operations. For better security, we recommend that you use a RAM user to make API calls.
    // Do not hard-code the AccessKey ID and AccessKey secret in your project code. Otherwise, the AccessKey pair may be leaked and compromise the security of all your resources.
    // This example shows how to obtain an AccessKey pair from environment variables to authenticate API requests. Before you run the code, configure the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
    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;
    }

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

        // A list of the source video URLs. The URLs must be URL-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, ','));
        // A list of job IDs. You can obtain job IDs from the response of the UploadMediaByURL API 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());
        }
    }
}