• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

uploading a file but want to restrict the type of files

 
Ranch Hand
Posts: 50
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using jsp for file uploading in my struts application,

i am able to upload a file but want to limit the type of files that can be uploaded. how can we restrict user to upload file with specified extension....the file should not be inserted in the daatabase if its of other type
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't restrict what gets uploaded, so you need to perform any required checks on the server before working with the data. Note that the file extension is not necessarily indicative of the file content, so you should perform a semantic check of that as well.
 
andrew ronchi
Ranch Hand
Posts: 50
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okk...cant we use javascript which ll check the extension and if its different other than d specification,it will give alertbox...?
 
Tim Moores
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Client-side JavaScript has no concept of files.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Javascript doesn't have access to input fields of "file" type for security reasons.
 
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Might people fall in love with java script, In struts 2 We have FileUploadInterceptor there you can specify the allowed file ContentType, maximum file size that can be uploaded and you can define allowed file extension types.
 
andrew ronchi
Ranch Hand
Posts: 50
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is ther any facility in struts 1...?? in my application,i want user to upload only pdf files...
and only those files should b inserted in database...if he tries to upload other files such as bmp,jpg...these files should not be inserted..
so how can i achieve this....??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic