Java/Spring Boot(70)
-
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 -
Spring boot X-Frame-Options 처리
iframe 사용시 에러 발생브라우져의 header 정보에서 확인할 수 있실제로는 Ext.window.Window 사용하여 팝업 실행하여 서버에 호출함chrome-error://chromewebdata/:1 Refused to display 'http://localhost/' in a frame because it set 'X-Frame-Options' to 'deny'. X-Frame-Options 값DENY – Prevents the site from being embedded in any iframe.SAMEORIGIN – Allows embedding only if the parent is from the same origin.ALLOW-FROM – Allows embedding only fro..
2024.12.26 -
Spring boot request header 정보 출력하기
Filter 사용415 에러 등이 발생했을 때, header값이 어떤 값이 들어왔는지 확인이 안될 때 사용하면 좋을 것 같음body는 한번 사용되면, 사라지기 때문에 ContentCachingRequestWrapper wrappedRequest로 받아서 별도 처리해야 함정상적으로 처리되면 body가 출력되지만, 에러가 발생하는 경우(415 등) body는 null값이 출력됨@Slf4j@Componentpublic class RequestLoggingFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOExc..
2024.12.13