aspose file tools*
The moose likes Java in General and the fly likes Image extension and mimetype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
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: 19542
    
  16

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image extension and mimetype
 
Similar Threads
Issue with Copy and Paste from external source to applet.
Image Upload - Jsp or servlet
problem with if-condition
FileDownloadServlet
How to get the path of an Uploaded file?