@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 {
courseUrl.transferTo(dir);
baseResponse.setResult(path+fileName);
}catch (Exception e){
System.out.println(e);
}
return baseResponse;
}
springboot上傳本地圖片到數據庫
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.