Код: Выделить всё
public static Map getImageType(byte[] imageContent) throws Exception {
Map result = new HashMap();
TikaConfig config = TikaConfig.getDefaultConfig();
MediaType mediaType = config.getMimeRepository().detect(new ByteArrayInputStream(imageContent), new Metadata());
MimeType mimeType = config.getMimeRepository().forName(mediaType.toString())
result.put("extn", mimeType.getExtension().replaceFirst(".", ""));
return result;
}
Приведенный выше код работает нормально для всех документов, имеющих расширения .pdf, .jpg, . csv, .txt, .bin, .jpeg и возвращают ожидаемое расширение Ex {extn=.pdf}. Но он не работает, если расширение файла .doc и .docx и возвращает пустое значение {extn=
Код: Выделить всё
Expecting to get the .doc and .docx file extension ex:{extn=.doc}Подробнее здесь: https://stackoverflow.com/questions/784 ... byte-array