문서 보기이전 판역링크맨 위로 이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요. <file java> public List<String> saveFiles(List<MultipartFile> files) throws RuntimeException { if (files == null || files.isEmpty()) return Collections.EMPTY_LIST; List<String> uploadNames = new ArrayList<>(); files.stream().forEach(file -> { String savedName = UUID.randomUUID().toString() + "_" + file.getOriginalFilename(); Path savePath = Paths.get(uploadPath, savedName); try { Files.copy(file.getInputStream(), savePath, StandardCopyOption.REPLACE_EXISTING); uploadNames.add(savedName); } catch (IOException e) { throw new RuntimeException(e); } }); return uploadNames; </file> <file java> public List<String> saveFiles(List<MultipartFile> files) throws RuntimeException { if (files == null || files.isEmpty()) return Collections.EMPTY_LIST; return files.stream().map(this::uploadFile).toList(); } private String uploadFile(MultipartFile file) throws RuntimeException { if (file == null || file.isEmpty()) throw new RuntimeException("File is empty"); String savedName = UUID.randomUUID() + "_" + file.getOriginalFilename(); Path savePath = Paths.get(uploadPath, savedName); try { // 파일 복사 Files.copy(file.getInputStream(), savePath, StandardCopyOption.REPLACE_EXISTING); // 썸네일 처리 - MIME 유형으로 이미지 확인 후 복사 if (file.getContentType() != null && file.getContentType().startsWith("image/")) { Path thumbnailPath = Paths.get(uploadPath, "s_" + savedName); Thumbnails.of(savePath.toFile()).size(200, 200).toFile(thumbnailPath.toFile()); } } catch (IOException e) { throw new RuntimeException(e); } return savedName; } </file> <file java> public ResponseEntity<Resource> getFile(String fileName) { Resource resource = new FileSystemResource(uploadPath + File.separator + fileName); if (!resource.isReadable()) resource = new FileSystemResource(uploadPath + File.separator + "default.ico"); HttpHeaders headers = new HttpHeaders(); try { headers.add("Content-Type", Files.probeContentType(resource.getFile().toPath())); } catch (IOException e) { throw new RuntimeException(e); } return ResponseEntity.ok().headers(headers).body(resource); } </file> java/fileupload.java.txt 마지막으로 수정됨: 2025/04/04 07:55저자 writer