Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restricting Type of file being uploaded

 
Vikram Virk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic