1.依赖
<!-- 此依赖网上仓库没有,需自己找到,手动安装到本地仓库 -->
<dependency>
<groupId>local</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
-
启动类 添加(此步是为了让文件支持强转):
@SpringBootApplication( exclude = {MultipartAutoConfiguration.class})@Bean(“multipartResolver”)
public CommonsMultipartResolver multipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding(“UTF-8”);
resolver.setMaxInMemorySize(10000);
return resolver;
}
3.代码:
public AttachmentDTO uploadVideo(MultipartFile multipartFile) {
//强转(步骤2就是为这铺垫)
CommonsMultipartFile cf = (CommonsMultipartFile)multipartFile;
DiskFileItem fi = (DiskFileItem) cf.getFileItem();
java.io.File source = fi.getStoreLocation();
// 获取视频时长
Encoder encoder = new Encoder();
MultimediaInfo m = null;
m = encoder.getInfo(source);
long ls = m.getDuration()/1000;
int hour = (int) (ls/3600);
int minute = (int) (ls%3600)/60;
int second = (int) (ls-hour
3600-minute
60);
}