This discussion is archived
2 Replies Latest reply: Jun 6, 2008 11:57 PM by 807591 RSS

upload file validations

807591 Newbie
Currently Being Moderated
hi ,
i want to validate FileAttachment If i give more than 2MB,it is not enter inside the loop at all .this is my code

if(attachmentFileName != null){
try{
InputStream inputStream = new FileInputStream(attachmentFileName);
if(attachmentFileName.length() > ApplicationDefs.TWO_MB){ addActionError("Sorry your file is size is greater than 2 MB");
return;
}
if(inputStream.available() == 0){
addActionError("Invalid file format");
return;
}
if(!isValidFileFormat(attachmentFileName)){
addActionError("Invalid file format");
return;
}

}catch(FileNotFoundException fne){
addActionError("Uploaded file not found");
return;
}catch(IOException io){
addActionError("Unable to read the uploaded file");
return;
}//end of try-catch
}//end of if

showing the following errors

15:36:47,339 ERROR [MultiPartRequest] org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (2264141) exceeds the configured maximum (2097152)

15:36:52,839 ERROR [FileUploadInterceptor] the request was rejected because its size (2264141) exceeds the configured maximum (2097152)

please any body help me

sreenu
  • 1. Re: upload file validations
    807591 Newbie
    Currently Being Moderated
    In the future, please post Servlet questions in the Servlet forum: [http://forum.java.sun.com/forum.jspa?forumID=33]

    The FileUpload is working perfectly? It throws exception when the file exceeds the size as yourself have definied in the filter configuration. If you rather want to handle that exception yourself, then put it in a try-catch block with a catch on SizeLimitExceededException.
  • 2. Re: upload file validations
    807591 Newbie
    Currently Being Moderated
    after placing inside the try,catch block also it's displaying same errors