全部产品
Search
文档中心

视频点播:媒体上传

更新时间:Jan 08, 2024

点播服务端提供丰富的上传接口,支持开发者采用不同的上传方式实现媒体上传。本文介绍Java SDK调用服务端上传接口的使用场景和调用示例。

使用场景

重要

本文仅提供API调用示例,即在点播服务中获取上传凭证和地址等操作示例。要实现完整的媒体文件上传逻辑,请参考下表跳转至对应的上传方式和使用场景。

接口

使用场景

获取音视频上传地址和凭证

  • OSS原生SDK上传场景下,用户应用服务器集成点播服务端SDK并调用相关接口获取或刷新上传地址和凭证。获取到的上传地址和凭证需要Base64解码后作为初始化OSS上传客户端实例的参数。详情请参见基于OSS原生SDK上传。其中,Java语言提供了基于OSS原生SDK上传的完整的媒体文件上传逻辑的Demo示例,其他语言可以参考实现,详情请参见通过视频点播API上传媒体文件

  • 点播客户端上传SDK场景下,用户应用服务器集成点播服务端SDK并调用相关接口获取或刷新上传地址和凭证。获取到的上传地址和凭证无需解码即可下发给客户端。详情请参见客户端上传SDK指引

刷新音视频上传凭证

获取图片上传地址和凭证

获取辅助媒资上传地址和凭证

URL批量拉取上传

  • 调用URL批量拉取上传接口实现离线拉取上传。这种方式可以免去先将文件下载到本地服务器或终端再使用上传SDK上传到点播的过程。

    说明

    URL拉取上传是异步任务,非实时,不保证时效性,一般提交后会在数小时、甚至数天内完成迁移上传。

  • 调用获取URL上传信息获取上传进度。

获取URL上传信息

注册媒资信息

前提条件

  • 调用接口前请先安装SDK。操作指引请参见安装

  • 调用接口前请先初始化客户端实例。操作指引请参见初始化

接口调用说明

  • 本文提供的接口调用示例均通过AccessKey初始化客户端实例。

  • 接口的参数解释和返回字段的详细说明请访问阿里云OpenAPI门户,在各接口右侧的文档页签查看。

  • 本文仅提供部分复杂接口的代码示例,其余接口的SDK代码示例,可以通过阿里云OpenAPI门户获取。访问阿里云OpenAPI门户,在接口的左侧参数配置页签,填写需要的参数信息并发起调用后,在右侧的SDK示例页签,选择SDK版本,选择目标语言,查看并下载示例代码。

  • 本文均以V1.0版本的SDK为例进行接口调用,如需获取V2.0版本的SDK示例,请在通过阿里云OpenAPI门户获取SDK示例时,指定到对应的SDK版本。image.png

接口调用示例

获取音/视频上传地址和凭证

调用CreateUploadVideo接口,完成获取音/视频上传地址和凭证功能。

阿里云OpenAPI门户地址:CreateUploadVideo

调用示例如下:

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;

/**
 *
 * 音频或视频获取上传凭证的示例
 */
public class AudioOrVideoCreateUploadDemo {

    /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai";  
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * 获取音/视频上传地址和凭证
     * @param client 发送请求客户端
     * @return CreateUploadVideoResponse 获取音/视频上传地址和凭证响应数据
     * @throws Exception
     */
    public static CreateUploadVideoResponse createUploadVideo(DefaultAcsClient client) throws Exception {
        CreateUploadVideoRequest request = new CreateUploadVideoRequest();
        request.setTitle("this is a sample");
        request.setFileName("filename.mp4");

        //UserData,用户自定义设置参数,用户需要单独回调URL及数据透传时设置(非必须)
        //JSONObject userData = new JSONObject();

        //UserData回调部分设置
        //消息回调设置,指定时以此为准,否则以全局设置的事件通知为准
        //JSONObject messageCallback = new JSONObject();
        //设置回调地址
        //messageCallback.put("CallbackURL", "http://192.168.0.1/16");
        //设置回调方式,默认为http
        //messageCallback.put("CallbackType", "http");
        //userData.put("MessageCallback", messageCallback.toJSONString());

        //UserData透传数据部分设置
        //用户自定义的扩展字段,用于回调时透传返回
        //JSONObject extend = new JSONObject();
        //extend.put("MyId", "user-defined-id");
        //userData.put("Extend", extend.toJSONString());

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

        return client.getAcsResponse(request);
    }
  
    /** 
     * 请求示例
     */
    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());
        }
    }
}

刷新音/视频上传凭证

调用RefreshUploadVideo接口,完成刷新音/视频上传凭证功能。

阿里云OpenAPI门户地址:RefreshUploadVideo

调用示例如下:

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;

/**
*
* 音频或视频刷新上传凭证的示例
*/
public class AudioOrVideoRefreshUploadDemo {

    /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai";  
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * 刷新音/视频上传凭证
     * @param client 发送请求客户端
     * @return RefreshUploadVideoResponse 刷新音/视频上传凭证响应数据
     * @throws Exception
     */
    public static RefreshUploadVideoResponse refreshUploadVideo(DefaultAcsClient client) throws Exception {
        RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
        //音频或视频ID
        request.setVideoId("<VideoId>");
        return client.getAcsResponse(request);
    }

    /** 
     * 请求示例
     */
    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());
        }
    }
}

获取图片上传地址和凭证

调用CreateUploadImage接口,完成获取图片上传地址和凭证功能。

阿里云OpenAPI门户地址:CreateUploadImage

调用示例如下:

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;

/**
 * 图片获取上传凭证的示例
 *
 */
public class ImageCreateUploadDemo {

    /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai";  
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * 获取图片上传地址和凭证
     * @param client 发送请求客户端
     * @return CreateUploadImageResponse 获取图片上传地址和凭证响应数据
     * @throws Exception
     */
    public static CreateUploadImageResponse createUploadImage(DefaultAcsClient client) throws Exception {
        CreateUploadImageRequest request = new CreateUploadImageRequest();
        //设置图片类型
        request.setImageType("default");
        //设置图片扩展名
        request.setImageExt("gif");
        //设置图片标题
        request.setTitle("this is a sample");

        //UserData,用户自定义设置参数,用户需要单独回调URL及数据透传时设置(非必须)
        JSONObject userData = new JSONObject();

        //UserData回调部分设置
        //消息回调设置,指定时以此为准,否则以全局设置的事件通知为准
        JSONObject messageCallback = new JSONObject();
        //设置回调地址
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        //设置回调方式,默认为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);
    }

    /** 
     * 请求示例
     */
    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());
        }
    }
}

获取辅助媒资上传地址和凭证

调用CreateUploadAttachedMedia接口,完成获取辅助媒资上传地址和凭证功能。

阿里云OpenAPI门户地址:CreateUploadAttachedMedia

调用示例如下:

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;

/**
 * 辅助媒资获取上传凭证的示例
 *
 */
public class AttachedMediaCreateUploadDemo {

     /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai";
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * 获取辅助媒资(水印、字幕等)上传地址和凭证
     * @param client 发送请求客户端
     * @return CreateUploadAttachedMediaResponse 获取辅助媒资上传地址和凭证响应数据
     * @throws Exception
     */
    public static CreateUploadAttachedMediaResponse createUploadAttachedMedia(DefaultAcsClient client) throws Exception {
        CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
        //设置业务类型
        request.setBusinessType("watermark");
        //设置文件扩展名
        request.setMediaExt("gif");
        //设置标题
        request.setTitle("this is a sample");

        //UserData,用户自定义设置参数,用户需要单独回调URL及数据透传时设置(非必须)
        JSONObject userData = new JSONObject();

        //UserData回调部分设置
        //消息回调设置,指定时以此为准,否则以全局设置的事件通知为准
        JSONObject messageCallback = new JSONObject();
        //设置回调地址
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        //设置回调类型,默认为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);
    }
    /** 
     * 请求示例
     */
    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批量拉取上传

调用UploadMediaByURL接口,完成URL批量拉取上传功能。

阿里云OpenAPI门户地址:UploadMediaByURL

调用示例如下:

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;

/**
 * URL批量拉取上传功能示例
 *
 */
public class AudioOrVideoUploadByUrl {

    /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai"; 
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * URL批量拉取上传
     *
     * @param client 发送请求客户端
     * @return UploadMediaByURLResponse URL批量拉取上传响应数据
     * @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");
        //视频源文件URL
        request.setUploadURLs(encodeUrl);

        //上传视频元数据信息
        JSONObject uploadMetadata = new JSONObject();
        //需要上传的视频源文件URL,与UploadURLs里的URL匹配才能生效
        uploadMetadata.put("SourceUrl", encodeUrl);
        //视频标题
        uploadMetadata.put("Title", "upload by url sample");

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

        //UserData,用户自定义设置参数,用户需要单独回调URL及数据透传时设置(非必须)
        JSONObject userData = new JSONObject();

        //UserData回调部分设置
        //消息回调设置,指定时以此为准,否则以全局设置的事件通知为准
        JSONObject messageCallback = new JSONObject();
        //设置回调地址
        messageCallback.put("CallbackURL", "http://192.168.0.0/16");
        //设置回调类型,默认为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);
    }

    /** 
     * 请求示例
     */
    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());
        }
    }

}

注册媒资信息

调用RegisterMedia接口,完成注册媒资信息功能。

阿里云OpenAPI门户地址:RegisterMedia

调用示例如下:

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;

/**
 * 媒资注册示例
 *
 */
public class MediaRegisterDemo {

    /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai";  
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * 注册媒资信息
     * @param client 发送请求客户端
     * @return RegisterMediaResponse 注册媒资信息响应数据
     * @throws Exception
     */
    public static RegisterMediaResponse registerMedia(DefaultAcsClient client) throws Exception {
        RegisterMediaRequest request = new RegisterMediaRequest();
        JSONArray metaDataArray = new JSONArray();
        JSONObject metaData = new JSONObject();
        //标题
        metaData.put("Title", "this is a sample");
        //源文件地址,文件名需要保证全局唯一。添加相同文件名称时关联唯一媒体ID。
        metaData.put("FileURL", "https://192.168.0.0/16.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4");
        //指定要注册的媒资元数据
        metaDataArray.add((metaData));
        request.setRegisterMetadatas(metaDataArray.toJSONString());
        return client.getAcsResponse(request);
    }

    /** 
     * 请求示例
     */
    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());
        }

    }

}

获取URL上传信息

调用GetURLUploadInfos接口,完成获取URL上传信息功能。

阿里云OpenAPI门户地址:GetURLUploadInfos

调用示例如下:

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;

/**
 * 获取URL上传信息示例
 */
public class URLUploadInfosGetDemo {
    
    /** 
     * 读取AccessKey信息
     */
    public static DefaultAcsClient initVodClient() throws ClientException {
    // 点播服务接入地域
    String regionId = "cn-shanghai";  
    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // 本示例通过从环境变量中读取AccessKey,来实现API访问的身份验证。运行代码示例前,请配置环境变量ALIBABA_CLOUD_ACCESS_KEY_ID和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;
    }

    /**
     * 获取URL上传信息
     *
     * @param client 发送请求客户端
     * @return GetURLUploadInfosResponse 获取URL上传信息响应数据
     * @throws Exception
     */
    public static GetURLUploadInfosResponse getURLUploadInfos(DefaultAcsClient client) throws Exception {
        GetURLUploadInfosRequest request = new GetURLUploadInfosRequest();

        //上传源视频URL列表,需要URLencode
        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, ','));
        //JobId列表,可以通过GetPlayInfo接口中返回的PlayInfo结构体中获取
        //request.setJobIds("exampleID1,exampleID2");

        return client.getAcsResponse(request);
    }

    /** 
     * 请求示例
     */
    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());
        }
    }
}