/**
* 文件上传
*
* @return 返回相对路径
* @return
* @throws Exception
*/
public static void fileUpload(MultipartFile file, String filePath) throws Exception {
// 判断是否有上传文件
if (Objects.isNull(file) || file.isEmpty() || Objects.isNull(file.getOriginalFilename())) {
throw new FileNotFoundException("文件上传失败");
}
File savefile = new File(filePath);
// 若保存文件的文件夹不存在则创建
if (!savefile.getParentFile().exists()) {
savefile.getParentFile().mkdirs();
}
logger.info("上传文件绝对路径: " + savefile.getPath());
file.transferTo(savefile);
}
文件上传1
最新推荐文章于 2024-09-14 19:44:09 发布