| 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
|
 |
 |
|
|
subject: Image extension and mimetype
|
|
|