22 lines
659 B
Kotlin
22 lines
659 B
Kotlin
package kr.co.vividnext.sodalive.utils
|
|
|
|
import kr.co.vividnext.sodalive.common.SodaException
|
|
import org.apache.tika.Tika
|
|
import org.springframework.web.multipart.MultipartFile
|
|
|
|
/**
|
|
* 이미지 파일인지 확인하고,
|
|
* GIF의 경우 외부 조건(gifAllowed)에 따라 허용 여부 판단
|
|
*/
|
|
fun validateImage(file: MultipartFile, gifAllowed: Boolean) {
|
|
val mimeType = Tika().detect(file.bytes)
|
|
|
|
if (!mimeType.startsWith("image/")) {
|
|
throw SodaException(messageKey = "image.error.only_image_allowed")
|
|
}
|
|
|
|
if (mimeType == "image/gif" && !gifAllowed) {
|
|
throw SodaException(messageKey = "image.error.gif_paid_only")
|
|
}
|
|
}
|