Below is the code snippet to get the file extension
public static Map<String, String> getImageType(byte[] imageContent) throws Exception {
Map<String, String> result = new HashMap<String, String>();
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;
}
Above code is working fine for all the document have expension .pdf, .jpg, .csv, .txt, .bin, .jpeg But it is not working when the file extension is .doc and .docx
Expecting to get the .doc and .docx file extension for byte[]