This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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: 7627
177
  • 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: 7627
177
  • 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: 28293
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....??
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic