Adds file type detection, and beefs up error states for file uploads
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user