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("/upload") public String upLoad(@RequestParam("email") String email, @RequestParam("username") String username, @RequestPart("headerImg") MultipartFile headerImg, // 使用 @RequestPart 对文件类型注解 @RequestPart("photos") MultipartFile[] photos) throws IOException { log.info("上传的信息:email={}, username={}. headerImg={}, photos={}", email, username, headerImg.getSize(), photos.length); if(!headerImg.isEmpty()){ String originalFilename = headerImg.getOriginalFilename(); headerImg.transferTo(new File("D:\\RenComp\\ehcache\\upload\\"+originalFilename)); } if (photos.length > 0){ for (MultipartFile photo : photos) { if (!photo.isEmpty()){ String originalFilename = photo.getOriginalFilename(); photo.transferTo(new File("D:\\RenComp\\ehcache\\upload\\"+originalFilename)); } } } return "redirect:/index.html"; }
|