1.引入相关依赖
2.配置application配置文件
3.创建启动类
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) //忽略查找数据库报错
@ComponentScan(basePackages = {"com.atguigu"})
public class VodApplication {
public static void main(String[] args) {
SpringApplication.run(VodApplication.class,args);
}
}
4.创建controller 和service层
public R uploadAlyunVideo(MultipartFile file){
String videoId = vodService.uploadVideoAlyun(file);
return R.ok().data("videoId",videoId);
}
@Override
public String uploadVideoAlyun(MultipartFile file) {
String fileName = file.getOriginalFilename();
String title = fileName.substring(0,fileName.lastIndexOf("."));
try {
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);
System.out.print("RequestId=" + response.getRequestId() + "\n"); //请求视频点播服务的请求ID
return response.getVideoId();
}catch(Exception e){
e.printStackTrace();
return null;
}
}
返回id即可将id传回前端()默认传1M 需要设置
spring.servlet.multipart.max-file-size=1024MB //单个文件小 spring.servlet.multipart.max-request-size=1024MB //多个文件大小
该文章描述了一个Java应用,通过SpringBoot框架进行配置,排除了DataSource自动配置,以避免数据库错误。主要功能是上传阿里云视频,通过VodService接口处理MultipartFile,创建UploadStreamRequest并使用UploadVideoImpl类上传视频流,返回视频ID。同时,文章提到了SpringBoot对上传文件大小的限制配置。
299

被折叠的 条评论
为什么被折叠?



