Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

problem in image File format

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am new to Spring MVC

I am uploading image into DataBase. Before uploading the image,validate the image file format .
The file format should be (*.png,*.jpeg,*.jpg,*.gif) ,for other types must show error. this is the logic.

this is my jsp
<form:form commandName="event" id="eventForm" name="eventForm" method="post" enctype="multipart/form-data">

<label>Event Photo</label>
<input type="file" name="eventPhoto"/>
<form:errors path="eventPhoto" cssClass="error" />
</form>

My validation here.

if((!eventForm.getEventPhoto().getContentType().equals("image/png"))&&
(!eventForm.getEventPhoto().getContentType().equals("image/x-png"))&&
(!eventForm.getEventPhoto().getContentType().equals("image/jpeg"))&&
(!eventForm.getEventPhoto().getContentType().equals("image/pjpeg"))&&
(!eventForm.getEventPhoto().getContentType().equals("image/jpg"))&&
(!eventForm.getEventPhoto().getContentType().equals("image/gif")))
{
errors.rejectValue("eventPhoto", "filetype.required");
}

the above code has worked in Safari, Firefox, Chrome. Except IE


when i upload *.bmp image in IE it accepts as --- image/pjpeg
.ico--------image/x-icon

it doesn't show error. IE accepts all image formats. This is the problem.

problem 2)

validate the image dimension ( height & weight) like 400*400

Thanks
 
Would you like to try a free sample? Today we are featuring tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic