aspose file tools*
The moose likes Struts and the fly likes Restricting Type of file being uploaded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Restricting Type of file being uploaded" Watch "Restricting Type of file being uploaded" New topic
Author

Restricting Type of file being uploaded

Vikram Virk
Greenhorn

Joined: Mar 13, 2006
Posts: 8
Please suggest some ways to restrict type and size of file being uploaded through JSP.I want only image file(gif,jpeg,bitmap..).My action class is

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {

NewsForm newsForm = (NewsForm) form;
FormFile myFile=null;
try{
myFile = newsForm.getTheFile();

String fileName = myFile.getFileName();

InputStream uploadInStream = myFile.getInputStream();

FileOutputStream fOut = new FileOutputStream("d:\\temp\\"
+ fileName);
int c=0;
while ((c=uploadInStream.read()) != -1) {
fOut.write(c);
} // while
fOut.flush();
fOut.close();
}

catch(FileNotFoundException fnfe){
}

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Restricting Type of file being uploaded