upload file validations

Discussions

General J2EE: upload file validations

  1. upload file validations (3 messages)

    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
  2. 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'
  3. Re: upload file validations[ Go to top ]

    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?
  4. the files which are browsed from browse button iam putting those data inside "attachmentFileName". iam passing this one into the FileInputStream