Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uploading a file but want to restrict the type of files

 
andrew ronchi
Ranch Hand
Posts: 48
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
Tim Moores
Bartender
Posts: 2674
33
  • Mark post as helpful
  • send pies
  • 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: 48
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 2674
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Client-side JavaScript has no concept of files.
 
Paul Clapham
Sheriff
Pie
Posts: 20715
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Javascript doesn't have access to input fields of "file" type for security reasons.
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 48
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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....??
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic