-
upload file validations (3 messages)
- Posted by: sreenu gantinapalli
- Posted on: June 06 2008 08:10 EDT
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 sreenuThreaded Messages (3)
- Re: upload file validations by Qu Jinlong on June 06 2008 13:14 EDT
- Re: upload file validations by Jyothish John on June 09 2008 08:55 EDT
- Re: upload file validations by sreenu gantinapalli on June 10 2008 01:31 EDT
- Re: upload file validations by Jyothish John on June 09 2008 08:55 EDT
-
Re: upload file validations[ Go to top ]
- Posted by: Qu Jinlong
- Posted on: June 06 2008 13:14 EDT
- in response to sreenu gantinapalli
This is because you set the max file size to be 2097152 for org.apache.commons.fileupload.FileUploadBase. you can catch the 'SizeLimitExceededException' to instead of the 'attachmentFileName.length() > ApplicationDefs.TWO_MB' -
Re: upload file validations[ Go to top ]
- Posted by: Jyothish John
- Posted on: June 09 2008 08:55 EDT
- in response to Qu Jinlong
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; }
Are you passing the "fileName" or the actual File Object as attachmentFileName? -
Re: upload file validations[ Go to top ]
- Posted by: sreenu gantinapalli
- Posted on: June 10 2008 01:31 EDT
- in response to Jyothish John
the files which are browsed from browse button iam putting those data inside "attachmentFileName". iam passing this one into the FileInputStream