Reputation: 1359
Is there a way or a library in Java to get the extension of an image file given its source as a byte array and its Mime type?
I am asking this since the same mime type can be used for different extensions.
Upvotes: 2
Views: 2221
Reputation: 715
As other said, it's not 100% reliable, but I know Apache Tika can do that.
You don't need the content if you already have the mime type:
MimeType type = MimeTypes.getDefaultMimeTypes().forName("image/png");
String extension = type.getExtension(); //.png
Upvotes: 3