개발자 도전기
[Spring] java.nio.file.NoSuchFileException 본문
회원 프로필 사진을 수정하는 메소드를 작성하던 도중 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 {
}
'개발공부 > Spring' 카테고리의 다른 글
[Spring] Lombok @RequiredArgsConstructor로 의존성 주입한 Bean이 null일 때 (0) | 2024.06.19 |
---|---|
[Spring] Negative matches: Did not match: (0) | 2024.06.12 |
[Spring] a bean of type 'org.apache.catalina.filters.CorsFilter' that could not be found. (0) | 2024.06.11 |
[Spring] @Value 어노테이션으로 주입한 값이 null일 때 (0) | 2024.06.07 |
[Spring] 컨트롤러로 요청 시 302 Found 응답 뜰 때 (0) | 2024.06.04 |