File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Image extension and mimetype Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Image extension and mimetype" Watch "Image extension and mimetype" New topic
Author

Image extension and mimetype

gani vojja
Greenhorn

Joined: Oct 12, 2011
Posts: 1
Hey Guys,

Is there any way i could find out the image extension and mimtype from stream(or uploaded file)?

final InputStream is = dataHandler.getInputStream();
final BufferedImage bi = ImageIO.read(is);

//Dimentions
System.out.println("width: " + bi.getWidth());
System.out.println("height: " + bi.getHeight());
System.out.println("type" + bi.getType());

I can use the Magic.getMagicmatch to get the mime type?
//final String mimeType = Magic.getMagicMatch(BYTESTREAM, false).getMimeType();

but, is there any way to get the extension from uploaded file using java?

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Use String's lastIndexOf method to find the last location of a dot, then return the substring from that location + 1. Be careful that lastIndexOf will return -1 when no dot is found, which also means there is no extension.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Image extension and mimetype
 
Similar Threads
How to get the path of an Uploaded file?
Image Upload - Jsp or servlet
FileDownloadServlet
Issue with Copy and Paste from external source to applet.
problem with if-condition