spring boot实现阿里云视频点播上传视频功能(复制粘贴即可)

时间:2021-05-19

目录:

1.spring boot实现阿里云视频点播上传视频(复制粘贴即可)

2.spring boot 实现阿里云视频点播 --删除视频

准备工作:

阿里云地址: https://ponentpublic class ConstantVodUtils implements InitializingBean { @Value("${aliyun.vod.file.keyid}") private String keyid; @Value("${aliyun.vod.file.keysecret}") private String keysecret; public static String ACCESS_KEY_SECRET; public static String ACCESS_KEY_ID; @Override public void afterPropertiesSet() throws Exception { ACCESS_KEY_ID = keyid; ACCESS_KEY_SECRET = keysecret; }}

VodController

@RestController@RequestMapping("/vod/video")@CrossOriginpublic class VodController { @Autowired private VodService vodService; //上传视频到阿里云 @PostMapping("uploadAlyiVideo") public String uploadAlyiVideo(MultipartFile file) { //返回上传视频id String videoId = vodService.uploadVideoAly(file); return videoId; }}

service

public interface VodService { //上传视频到阿里云 String uploadVideoAly(MultipartFile file);}@Servicepublic class VodServiceImpl implements VodService { @Override public String uploadVideoAly(MultipartFile file) { try { //accessKeyId, accessKeySecret //fileName:上传文件原始名称 String fileName = file.getOriginalFilename(); //title:上传之后显示名称 String title = fileName.substring(0, fileName.lastIndexOf(".")); //inputStream:上传文件输入流 InputStream inputStream = file.getInputStream(); UploadStreamRequest request = new UploadStreamRequest(ConstantVodUtils.ACCESS_KEY_ID,ConstantVodUtils.ACCESS_KEY_SECRET, title, fileName, inputStream); UploadVideoImpl uploader = new UploadVideoImpl(); UploadStreamResponse response = uploader.uploadStream(request); String videoId = null; if (response.isSuccess()) { videoId = response.getVideoId(); } else { //如果设置回调URL无效,不影响视频上传,可以返回VideoId同时会返回错误码。其他情况上传失败时,VideoId为空,此时需要根据返回错误码分析具体错误原因 videoId = response.getVideoId(); } return videoId; }catch(Exception e) { e.printStackTrace(); return null; } }}

界面简单编写

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body><form method="post" enctype="multipart/form-data" action="http://127.0.0.1:8003/vod/video/uploadAlyiVideo"> <input type="file" name="file"/> <input type="submit" value="提交"/></form></body></html>

上传成功后返回视频id

且在阿里云点播控制台看到视频已经上传

到此这篇关于spring boot实现阿里云视频点播上传视频(复制粘贴即可)的文章就介绍到这了,更多相关spring boot阿里云视频点播上传视频内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章