文档:服务端SDK->Java SDK->媒资管理
https://help.aliyun.com/document_detail/61065.html?spm=a2c4g.11186623.6.831.654b3815cIxvma#h2—div-id-deletevideo-div-7

一、后端

1、service

接口

  1. void removeVideo(String videoId);

实现

  1. @Override
  2. public void removeVideo(String videoId) {
  3. try{
  4. DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(
  5. ConstantPropertiesUtil.ACCESS_KEY_ID,
  6. ConstantPropertiesUtil.ACCESS_KEY_SECRET);
  7. DeleteVideoRequest request = new DeleteVideoRequest();
  8. request.setVideoIds(videoId);
  9. DeleteVideoResponse response = client.getAcsResponse(request);
  10. System.out.print("RequestId = " + response.getRequestId() + "\n");
  11. }catch (ClientException e){
  12. throw new GuliException(20001, "视频删除失败");
  13. }
  14. }

2、controller

  1. @DeleteMapping("{videoId}")
  2. public R removeVideo(@ApiParam(name = "videoId", value = "云端视频id", required = true)
  3. @PathVariable String videoId){
  4. videoService.removeVideo(videoId);
  5. return R.ok().message("视频删除成功");
  6. }

二、前端

1、定义api

api/edu/vod.js

  1. import request from '@/utils/request'
  2. const api_name = '/admin/vod/video'
  3. export default {
  4. removeById(id) {
  5. return request({
  6. url: `${api_name}/${id}`,
  7. method: 'delete'
  8. })
  9. }
  10. }

2、组件方法

views/edu/course/chapter.vue

import vod from '@/api/edu/vod'


beforeVodRemove(file, fileList) {
  return this.$confirm(`确定移除 ${file.name}?`)
},
handleVodRemove(file, fileList) {
  console.log(file)
  vod.removeById(this.video.videoSourceId).then(response=>{
    this.$message({
      type: 'success',
      message: response.message
    })
  })

},