问题描述
如何使用使用视频点播JAVA-SDK 上传媒资,我们需要那些准备工作
环境准备
- 本文使用(IntelliJ IDEA) 作为JAVA IDE
- Java-SDK 地址
创建maven 项目
添加SDK 依赖
若新建项目没有其他依赖, 需要在pom.xml配置中添加<dependencies>
标签
<dependencies>
<dependency>
<groupId>com.volcengine</groupId>
<artifactId>volc-sdk-java</artifactId>
<version>1.0.22</version>
</dependency>
</dependencies>
IDEA 会自动安装下载依赖 如无响应或更换 SDK
版本,执行Reload Project
导入 demo 代码
volc-java-sdk-uploadMediaDemo 新建VodUploadMediaDemo测试类,添加AK,SK SpaceName 等配置,并选择本地上传文件路径。
package com.volcengine.example.vod.upload;
import com.alibaba.fastjson.JSON;
import com.volcengine.model.beans.Functions;
import com.volcengine.service.vod.IVodService;
import com.volcengine.service.vod.impl.VodServiceImpl;
import com.volcengine.service.vod.model.request.VodUploadMediaRequest;
import com.volcengine.service.vod.model.response.VodCommitUploadInfoResponse;
import java.util.ArrayList;
import java.util.List;
public class VodUploadMediaDemo {
public static void main(String[] args) {
IVodService vodService = VodServiceImpl.getInstance();
// call below method if you dont set ak and sk in ~/.vcloud/config
vodService.setAccessKey("your ak");
vodService.setSecretKey("your sk");
String space = "your space name";
String filePath = "your file path";
List<Functions> functionsList = new ArrayList<>();
Functions getMetaFunc = Functions.GetMetaFunction();
functionsList.add(getMetaFunc);
Functions snapShotFunc = Functions.SnapShotFunction(2.3);
functionsList.add(snapShotFunc);
VodUploadMediaRequest vodUploadMediaRequest = VodUploadMediaRequest.newBuilder()
.setSpaceName(space)
.setFilePath(filePath)
.setFunctions(JSON.toJSONString(functionsList))
.build();
try {
VodCommitUploadInfoResponse vodCommitUploadInfoResponse = vodService.uploadMedia(vodUploadMediaRequest);
if (vodCommitUploadInfoResponse.getResponseMetadata().hasError()) {
System.out.println(vodCommitUploadInfoResponse.getResponseMetadata().getError());
System.exit(-1);
}
System.out.println(vodCommitUploadInfoResponse.toString());
System.out.println(vodCommitUploadInfoResponse.getResult().getData().getVid());
System.out.println(vodCommitUploadInfoResponse.getResponseMetadata().getRequestId());
} catch (Exception e) {
e.printStackTrace();
}
}
}
测试上传成功
如果您有其他问题,欢迎您联系火山引擎技术支持服务