22 lines
575 B
Kotlin
22 lines
575 B
Kotlin
package net.halfbinary.scavengerhuntapi.service
|
|
|
|
import org.apache.tika.Tika
|
|
import org.apache.tika.config.TikaConfig
|
|
import org.springframework.stereotype.Service
|
|
|
|
|
|
@Service
|
|
class FileProbeService {
|
|
private val tika = Tika()
|
|
|
|
fun getFileType(fileBytes: ByteArray): String {
|
|
return tika.detect(fileBytes)
|
|
}
|
|
|
|
fun getFileExtension(fileType: String): String {
|
|
return TikaConfig.getDefaultConfig().mimeRepository.forName(fileType).extension
|
|
}
|
|
fun isImageType(fileType: String): Boolean {
|
|
return fileType.startsWith("image")
|
|
}
|
|
} |