@PostMapping("inster")
public BaseResponse insterCourse(@RequestParam(value = "courseUrl") MultipartFile courseUrl){
BaseResponse baseResponse = BaseResponse.initialize();
if (StringUtils.isEmpty(courseUrl)){
baseResponse.setCode(1);
baseResponse.setMsg("文件不能为空");
return baseResponse;
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(new Date());
String path = "E:/var/uploaded_files/"+date+"/";
UUID uuid = UUID.randomUUID();
String originalFilename = courseUrl.getOriginalFilename();
String extendName = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
String fileName = uuid.toString() + extendName;
File dir = new File(path, fileName);
File filepath = new File(path);
if (!filepath.exists()){
filepath.mkdirs();
}
try {
springboot上传本地图片到数据库
最新推荐文章于 2025-06-10 09:48:46 发布