1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| @PostMapping("/uploadfile") public void uploadfile(@RequestParam MultipartFile file) throws IOException {
String filename = file.getOriginalFilename(); String uuid = UUID.randomUUID().toString(); String suffix = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase(); String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); String fileName = uuid + "." + suffix; String path = "F:/file/" + date + "/" + fileName;
File file1 = new File(path);
if (!file1.getParentFile().exists()) { file1.getParentFile().mkdirs(); }
file.transferTo(file1);
}
|