>  Q&A  >  본문

사용자 이미지를 업로드하지 않고 데이터를 편집할 때 오류 방지

그래서 사용자의 데이터를 업데이트할 때 이미 데이터베이스에 사용자의 이미지를 업로드했는데도 이미지를 다시 업로드하려는 오류가 발생했습니다. 이미지를 업로드하지 않고 사용자를 저장하고 업로드된 이미지를 내 데이터베이스에 유지하는 방법을 알려주실 수 있나요?

오류는 java.IOException입니다: 이미지 파일을 저장할 수 없습니다:

원인: java.nio.file.DirectoryNotEmptyException: profile-image/4

이것이 내 컨트롤러입니다

@PostMapping("/profile/save")
public String saveProfile(Profile profile, Model model, @RequestParam("image") MultipartFile multipartFile,@RequestParam(value="userId", required=false) Long userId) throws IOException {
profile.setUser(userRepo.findById(userId).get());
String fileName = StringUtils.cleanPath(multipartFile.getOriginalFilename()) ;
String uploadDir - "profile-image/"+ profile.getId();
FileUploadUtil.saveFile(uploadDir, fileName, multipartFile);
profile.setProfileImg(fileName);
profileService.saveProfile(profile);
return "redirect:/user/profile";

P粉707235568P粉707235568185일 전285

모든 응답(1)나는 대답할 것이다

  • P粉156532706

    P粉1565327062024-04-01 09:38:55

    당신의 FileUploadUtil수업에 버그가 있습니다. 이 디렉토리는 디렉토리가 존재하지 않거나 존재하는 경우에만 생성되어야 합니다:

    으아악

    회신하다
    0
  • 취소회신하다