dcsimg
Get Image type using Java
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sunil_daryani
Posted On:   Monday, February 25, 2008 07:44 AM

Hi. I want my user to upload a image file. I am able to get inputstream for that file (using commonsFileupload)
but want to do server side validation whether that file is
a valid image file and if so then of what type (gif, jpeg etc)
before saving it. I am using ImageIO which provides me
with the image height, width and for invalid images
I get exception but for valid images How can I find the image type?

Any ideas please.

Re: Get Image type using Java

Posted By:   Stephen_McConnell  
Posted On:   Monday, February 25, 2008 10:02 AM

Aside from looking at the file extension, I don't think there is a way of determining this by just looking at the binary file.


An operating system relies on the file extension to launch the program that will interpret the image format and then render that image. Without that valid file extension, no operating system will upload and render an image. If you try to change the file extension, then the Operating system will usually send you a message telling you that if you do that, it will no longer be responsible for interpreting the image.


So.... rely on the file extension... if it is not there, throw an exception or don't let the person upload it.


Stephen McConnell

About | Sitemap | Contact