Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발자 도전기

[Spring] java.nio.file.NoSuchFileException 본문

개발공부/Spring

[Spring] java.nio.file.NoSuchFileException

jnnjnn 2024. 6. 19. 14:17

 

회원 프로필 사진을 수정하는 메소드를 작성하던 도중 NoSuchFileException이 발생했다.

 

C:\Users\user\AppData\Local\Temp\tomcat.8080.6497677539176642649\work\Tomcat\localhost\ROOT\upload_fbf7e74c_7d28_4e24_bc4f_97a5b0b6379a_00000008.tmp

이 존재하지 않는다는 로그가 뜬다.

 

@PutMapping("users/{id}")
public ResponseEntity updateUser(User user, Authentication authentication,
                                 @RequestParam(value = "profileImage[]", required = false) 
                                 MultipartFile profileImage) throws IOException {
                                 }

 

이유는 User에서 다음과 같은 필드들을 사용중이었는데 MultipartFile을 받는 profileImage[]와 이름이 동일해서 발생한 것

 

@Data
public class User {
    private Integer id;
    private String email;
	....
    private List<String> authority;
    private UserFile profileImage;
}

 

 

변수 이름을 profileImages 로 바꾸고 프론트에서도 profileImages라는 이름으로 넘겨주니 해결되었다 !

 

@PutMapping("users/{id}")
public ResponseEntity updateUser(User user, Authentication authentication,
                                 @RequestParam(value = "profileImages[]", required = false) 
                                 MultipartFile profileImage) throws IOException {
                                 }