spring boot(52)
-
Spring boot java.lang.IllegalStateException: No primary or single unique constructor found for interface javax.servlet.http.HttpServletRequest
Spring boot 3.x 부터는 javax.servlet.http.HttpServletRequest를 지원하지 않음jakarta.servlet.http.HttpServletRequest를 사용해야 함
2024.12.28 -
Spring boot 외부 디렉토리를 static으로 인식하기
외부 디렉토리를 static으로 설정spring.web.resources.static-locations=file:/uploads/여러 디렉토리를 static으로 설정spring.web.resources.static-locations="file:/uploads/classpath:/static/"
2024.12.27 -
Spring boot 업로드 파일명 중복 피하기
filePath 정보를 계속 변경해서 while문으로 존재여부를 확인하는게 중요@PostMapping("/upload")public ResponseEntity handleFileUpload(@RequestParam("file") MultipartFile file) throws IOException { // Define the directory where files will be saved String uploadDir = "uploads/"; // Ensure the directory exists Path uploadPath = Paths.get(uploadDir); if (!Files.exists(uploadPath)) { Files.createDirectorie..
2024.12.26 -
Spring boot 파일업로드 OutOfMemoryError 고려사항
작은 파일public Map upload(@RequestParam("file") MultipartFile file) { Path filePath = uploadPath.resolve(file.getOriginalFilename()); Files.write(filePath, file.getBytes());큰 파일public Map upload(@RequestParam("file") MultipartFile file) { Path filePath = uploadPath.resolve(newFilename); Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
2024.12.26 -
Spring boot 업로드 디렉토리 설정하기
application.ymlfile: upload-dir: /path/uploadsController@Value("${file.upload-dir}")private String uploadDir;
2024.12.26 -
Spring boot Sencha 연동 파일 업로드 구성
Map을 통해서 응답 처리해야 함Case1@PostMapping("/location/upload")public ResponseEntity uploadFile(@RequestParam("file") MultipartFile file) { try { // Handle file storage Path path = Paths.get("uploads/" + file.getOriginalFilename()); Files.write(path, file.getBytes()); // Success response return ResponseEntity.ok(Map.of("success", true, "message", "File uploaded succ..
2024.12.26