Skip to content

Commit

Permalink
refactor: 이미지 업로드 시 이름 표기 방식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Combi153 committed Apr 29, 2024
1 parent e714afe commit 085c182
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,27 @@ class ProductReviewImageUploader(
private fun upload(image: MultipartFile): String {
ProductReviewImageType.validateSupported(image.contentType)
val fileName = UUID.randomUUID()
val path = "$directory$fileName.${image.originalFilename}"
val path = "$directory$fileName${parseFileExtension(image)}"

return uploadOrThrow(path, image)
}

private fun parseFileExtension(image: MultipartFile): String {
return image.originalFilename?.let {
".${it.substringAfterLast(FILE_EXTENSION_DELIMITER)}"
} ?: EMPTY_EXTENSION
}

private fun uploadOrThrow(path: String, image: MultipartFile): String {
try {
return imageStorageService.upload(path, image)
} catch (e: Exception) {
throw ProductReviewException(FAILED_REVIEW_IMAGE_UPLOAD)
}
}

companion object {
private const val FILE_EXTENSION_DELIMITER = '.'
private const val EMPTY_EXTENSION = ""
}
}

0 comments on commit 085c182

Please sign in to comment.