트러블 슈팅이 일어나게 된 원인 : 현재 서비스에서 기본이미지로 바꿀 경우 프론트에서 null을 보내준다. 따라서 이미지 파일에 null 이 들어온다면 return null을 하고 아닐 경우는 S3에 이미지를 업로드 한다.
String profileKey = image.map(imageFile -> {
String key = User.class.getSimpleName()
.toLowerCase()
+ "s"
+ "/" + userId.toString()
+ "/profile/"
+ UUID.randomUUID()
+ this.s3Uploader.getExtension(imageFile);
return this.s3Uploader.upload(
Bucket.IMAGE,
imageFile,
key,
S3Uploader.imageExtensions
);
}
)
.orElse(null);
String profileKey = image.map(imageFile -> {
//추가
if (imageFile.isEmpty()) {
return null;
}
String key = User.class.getSimpleName()
.toLowerCase()
+ "s"
+ "/" + userId.toString()
+ "/profile/"
+ UUID.randomUUID()
+ this.s3Uploader.getExtension(imageFile);
return this.s3Uploader.upload(
Bucket.IMAGE,
imageFile,
key,
S3Uploader.imageExtensions
);
}
)
.orElse(null);
MultipartFile로 이미지를 받을 때 파일을 보내지 않으면 null값으로 예상했지만,
null값이 아니였음!
따라서 .isEmty() 로 처리를 해줘야 한다.