SpringBoot接入腾讯云云点播视频上传(一)

发布时间:2022-07-04 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了SpringBoot接入腾讯云云点播视频上传(一)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

这里我整理了相关的参考链接

腾讯云点播快速入门案例

GITHub腾讯点播服务端上传文档参考

VOD Java SDK 是基于云点播上传功能(里面包含所需的jar包)

腾讯云社区 从零开始使用腾讯云Java SDK

快速入门

到腾讯云控制台

访问密钥 --> API密钥管理 --> 新建密钥 --> 获取 SecretId: SecretKey https://console.cloud.tencent.COM/cam/capi

新建sPRingboot项目

腾讯云所需的依赖pom.XMl如下


       <dePEndency>
            <groupId>com.tencentcloudapi</groupId>
            <artifactId>tencentcloud-sdk-java</artifactId>
            <!-- go to https://seArch.maven.org/search?q=tencentcloud-sdk-java and get the latest version. -->
            <!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询所有版本,最新版本如下 -->
            <version>3.1.363</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <dependency>
            <groupId>com.qcloud</groupId>
            <artifactId>vod_api</artifactId>
            <version>2.1.4</version>
        </dependency>
        <dependency>
            <groupId>com.qcloud</groupId>
            <artifactId>cos_api</artifactId>
            <version>5.6.8</version>
        </dependency>
@H_304_41@

使用SDK示例流程

    public static void main(String[] args) {
        try {
            Credential cred = new Credential("SecretId", "secretKey");
            CvmClient client = new CvmClient(cred, "ap-shanghai");
            DescribeinstancesRequest req = new DescribeInstancesRequest();
            DescribeInstancesResponse resp = client.DescribeInstances(req);
            System.out.println(DescribeInstancesResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }
  • 详细版
    @Test
    void contextLoads() {
        try {
            // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
            Credential cred = new Credential("secretId", "secretKey");
//            cred.setSecretId("secretId");
//            //个人API密钥中的Secret Key
//            cred.setSecretKey("secretKey");
            // 实例化一个http选项,可选的,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            //  从3.1.16版本开始, 单独设置 HTTP 代理
            // httpProfile.setProxyHost("真实代理ip");
            // httpProfile.setProxyPort(真实代理端口);
            httpProfile.setReqMethod("GET"); // get请求(默认为post请求)
            httpProfile.setProtocol("https://");  // 在外网互通的网络环境下支持http协议(默认是https协议),请选择(https:// or http://)
            httpProfile.setConnTimeout(30); // 请求连接超时时间,单位为秒(默认60秒)
            httpProfile.setWriteTimeout(30);  // 设置写入超时时间,单位为秒(默认0秒)
            httpProfile.setReadTimeout(30);  // 设置读取超时时间,单位为秒(默认0秒)
            httpProfile.setEndpoint("cvm.ap-shanghai.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)
            // 实例化一个client选项,可选的,没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setSignMethod("HmacSHA256"); // 指定签名算法(默认为HmacSHA256)
            // 自3.1.80版本开始,SDK 支持打印日志。
            clientProfile.setHttpProfile(httpProfile);
            clientProfile.setDebug(true);
            // 从3.1.16版本开始,支持设置公共参数 Language, 默认不传,选择(ZH_CN or EN_US)
            clientProfile.setLanguage(Language.EN_US);
            // 实例化要请求产品(以cvm为例)的client对象,clientProfile是可选的
            CvmClient client = new CvmClient(cred, "ap-shanghai", clientProfile);
            // 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。
            DescribeInstancesRequest req = new DescribeInstancesRequest();
            // 填充请求参数,这里request对象的成员变量即对应接口的入参
            // 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义
            Filter respFilter = new Filter(); // 创建Filter对象, 以zone的维度来查询cvm实例
            respFilter.setName("zone");
            respFilter.setValues(new String[] { "ap-shanghai-1", "ap-shanghai-2" });
            req.setfilters(new Filter[] { respFilter }); // Filters 是成员为Filter对象的列表
            // 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的
            // 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应
            DescribeInstancesResponse resp = client.DescribeInstances(req);
            // 输出json格式的字符串回包
            System.out.println(DescribeInstancesResponse.toJsonString(resp));
            // 也可以取出单个值。
            // 你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义
            System.out.println(resp.gettotalCount());
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }

结果

没有数据是因为我服务器没有实例 具体可参考 https://cloud.tencent.com/document/product/598/43332

SpringBoot接入腾讯云云点播视频上传(一)

脚本宝典总结

以上是脚本宝典为你收集整理的SpringBoot接入腾讯云云点播视频上传(一)全部内容,希望文章能够帮你解决SpringBoot接入腾讯云云点播视频上传(一)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。