package cn.iocoder.yudao.module.ai.util;
|
|
import cn.hutool.core.util.StrUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.tika.Tika;
|
|
/**
|
* 文件类型 Utils
|
*
|
* @author 芋道源码
|
*/
|
@Slf4j
|
public class FileTypeUtils {
|
|
private static final Tika TIKA = new Tika();
|
|
/**
|
* 已知文件名,获取文件类型,在某些情况下比通过字节数组准确,例如使用 jar 文件时,通过名字更为准确
|
*
|
* @param name 文件名
|
* @return mineType 无法识别时会返回“application/octet-stream”
|
*/
|
public static String getMineType(String name) {
|
return TIKA.detect(name);
|
}
|
|
/**
|
* 判断是否是图片
|
*
|
* @param mineType 类型
|
* @return 是否是图片
|
*/
|
public static boolean isImage(String mineType) {
|
return StrUtil.startWith(mineType, "image/");
|
}
|
|
}
|