A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Image extension and mimetype
Joined: Oct 12, 2011
Oct 12, 2011 11:51:02
Is there any way i could find out the image extension and mimtype from stream(or uploaded file)?
is = dataHandler.getInputStream();
bi = ImageIO.read(is);
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?
mimeType = Magic.getMagicMatch(BYTESTREAM, false).getMimeType();
but, is there any way to get the extension from uploaded file using
Joined: Oct 27, 2005
Oct 12, 2011 12:21:05
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:
subject: Image extension and mimetype
Image Upload - Jsp or servlet
problem with if-condition
Issue with Copy and Paste from external source to applet.
How to get the path of an Uploaded file?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014