测试
debug
方法
@RequestMapping(value = "/test",method = RequestMethod.POST)
public void fileUpload(MultipartFile file){
// 文件名
String originalFilename = file.getOriginalFilename();
// 文件名前缀
String fileName = file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf("."));
// 文件名后缀
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
// 文件类型
String fileType = file.getContentType();
// 文件大小
String fileSize = String.valueOf(file.getSize());
log.info("文件名: {}",originalFilename);
log.info("文件名前缀: {}",fileName);
log.info("文件名后缀: {}",fileSuffix);
log.info("文件类型: {}",fileType);
log.info("文件大小: {}",fileSize);
}
输出结果
21:53:50.771 [http-nio-9696-exec-2] INFO c.r.r.s.f.FileController - [fileUpload,74] - 文件名: 1690877720980789.mp4
21:53:51.596 [http-nio-9696-exec-2] INFO c.r.r.s.f.FileController - [fileUpload,75] - 文件名前缀: 1690877720980789
21:53:52.236 [http-nio-9696-exec-2] INFO c.r.r.s.f.FileController - [fileUpload,76] - 文件名后缀: .mp4
21:53:53.245 [http-nio-9696-exec-2] INFO c.r.r.s.f.FileController - [fileUpload,77] - 文件类型: video/mp4
21:53:56.091 [http-nio-9696-exec-2] INFO c.r.r.s.f.FileController - [fileUpload,78] - 文件大小: 1096828