aspose file tools*
The moose likes Struts and the fly likes uploading a file but want to restrict the type of files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "uploading a file but want to restrict the type of files" Watch "uploading a file but want to restrict the type of files" New topic
Author

uploading a file but want to restrict the type of files

andrew ronchi
Ranch Hand

Joined: Nov 03, 2011
Posts: 48

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
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Nov 03, 2011
Posts: 48

okk...cant we use javascript which ll check the extension and if its different other than d specification,it will give alertbox...?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Client-side JavaScript has no concept of files.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

And Javascript doesn't have access to input fields of "file" type for security reasons.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

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.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
andrew ronchi
Ranch Hand

Joined: Nov 03, 2011
Posts: 48

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....??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: uploading a file but want to restrict the type of files