发布时间:2024-07-10 11:01
其他略
com.aliyun
aliyun-java-sdk-core
com.aliyun.oss
aliyun-sdk-oss
com.aliyun
aliyun-java-sdk-vod
com.aliyun
aliyun-sdk-vod-upload
com.alibaba
fastjson
org.json
json
com.google.code.gson
gson
joda-time
joda-time
注意:其中上传部分的jar报需要手动安装到本地maven哭库
依次点击下载
下载下来,解压到某一位置,在如图对应目录下打开cmd窗口,执行如下命令:
mvn install:install-file -DgroupId=com.aliyun -DartifactId=aliyun-sdk-vod-upload -Dversion=1.4.11 -Dpackaging=jar -Dfile=aliyun-java-vod-upload-1.4.11.jar
我这里装完出错了,这可能是因为本地处理过多个项目,maven仓库胡乱配置了好几次,装到其他地方去了。比如我这里装到我上个公司的某个项目的maven库中了。但是我现在做的这个项目,用的就不是这个maven库。!
这个问题我以前解决过好几次,忘了。写的日志也忘了写哪里去了,我很奇怪的一点是,我明明配置了mavenhome,对应的仓库地址是我仙子啊项目的maven库地址。可是,他竟然按照这个地址安装的 。
所以,我先解决问题,以后再探究为什么吧。既然是按照这里来的,那么我们就给他改成笨项目的地址呗。
/**
* @program: education
* @description:
* @author: WL
* @create: 2020-06-20 23:42
**/
@Controller
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {
@Autowired
private VodService vodService;
@PostMapping("uploadALiYunVideo")
public R uploadALiYunVideo(MultipartFile file){
String videoId= vodService.uploadALiYunVideo(file);
return R.ok().data("videoId",videoId);
}
}
/**
* @program: education
* @description:
* @author: WL
* @create: 2020-06-20 23:49
**/
@Service
public class VodServiceImpl implements VodService {
@Override
public String uploadALiYunVideo(MultipartFile file) {
try {
//原文件名称
String fileName= file.getOriginalFilename();
//上传后显示的名称
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 uploadVideo= new UploadVideoImpl();
UploadStreamResponse response = uploadVideo.uploadStream(request);
String videoId=null;
if (response.isSuccess()){
videoId= response.getVideoId();
}else {
videoId= response.getVideoId();
}
return videoId;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
}
1)创建工具类实现接口
/**
* @program: education
* @description:
* @author: WL
* @create: 2020-06-21 00:30
**/
@Component
public 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;
}
}
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
通过tomcat上传,tomcat有文件大小设置:限制1m
修改配置:
elementui样式修改 此部分省略
1、单个删除
1)初始化对象
/**
* @program: education
* @description: 阿里云视频点播初始化客户端
* @author: WL
* @create: 2020-06-21 12:53
**/
public class InitVodClient {
public static DefaultAcsClient initVodClient(String accessKeyId,String accessKeySecret) throws ClientException {
String regionId="cn-shanghai";//点播服务接入区域
DefaultProfile profile=DefaultProfile.getProfile(regionId,accessKeyId,accessKeySecret);
DefaultAcsClient client= new DefaultAcsClient(profile);
return client;
}
}
2)实现
@DeleteMapping("removeAliYunVideo/{id}")
public R removeAliYunVideo(@PathVariable String id){
try{
//初始化对象
DefaultAcsClient client= InitVodClient.initVodClient(ConstantVodUtils.ACCESS_KEY_ID,ConstantVodUtils.ACCESS_KEY_SECRET);
//创建删除视频request对象
DeleteVideoRequest request= new DeleteVideoRequest();
//设置视频id
request.setVideoIds(id);
//调用初始化客户端对象实现删除
client.getAcsResponse(request);
return R.ok();
}catch (Exception e){
e.printStackTrace();
throw new EducationException(20001,"删除视频失败");
}
}
3)前端api中定义接口路径
removeAliYunVideo(id){
return request({
url:'/eduvod/video/removeAliYunVideo/'+id,
method:'delete'
})
}
4)页面调用
略
2、批量删除
1)controller
批量传入id值
//批量删除多个阿里云视频
@DeleteMapping("delete-batch")
public R deleteBatch(@RequestParam("videoList")List videoList){
vodService.removeALiYunVideos(videoList);
return R.ok();
}
2)service
/**
* @Description: 批量删除阿里云视频
* @Param:
* @Author WL
* @date: 2020/6/22
* @return:
*/
@Override
public void removeALiYunVideos(List videoList) {
try{
DefaultAcsClient client= InitVodClient.initVodClient(ConstantVodUtils.ACCESS_KEY_ID,ConstantVodUtils.ACCESS_KEY_SECRET);
DeleteVideoRequest request = new DeleteVideoRequest();
//TODO 注意此方法,注意是那个包的!!!
String videoIds= StringUtils.join(videoList.toArray(),",");
request.setVideoIds(videoIds);
client.getAcsResponse(request);
}catch (Exception e){
e.printStackTrace();
throw new EducationException(20001,"删除视频失败了");
}
}
1>初始化客户端与删除部分用一个即可
2>注意一个新的工具类的使用,其可以将list中的值以“,”分割拼接成如:“1,2,3”格式。注意其属于哪个包:org.apache.commons.lang.StringUtils;
libgdx游戏引擎教程实战篇(四)移植俄罗斯方块(附源码)
Visual Studio中C++部分的官方文档链接【微软(Microsoft)所有产品的官方文档链接】
[vscode]代码规范ESLint + Prettier 在vue项目中的使用和冲突解决[完美解决]
Google Earth Engine (GEE) 导出数据到Drive account (Google Drive)目录
CartPole 强化学习详解2 - Policy Gradient
【服务器数据恢复】OceanStor存储中NAS卷数据丢失的数据恢复案例
Android版OpenCV图像处理技术亲自验证[三十二]之图像自适应阈值操作(附源码)