0

Uploader is reading any file larger than 100kb but files having size lower than 100kb multipartFile object is null

The command object is

class UploadInfoListCommand implements Validateable{   MultipartFile infoMasterFile   String localeFileileExtension

  static constraints = {
    infoMasterFile  validator: { val, obj ->
      if ( val == null ) {
        return false
      }
      if ( val.empty ) {
        return false
      }

      ['xlsx'].any { extension -> // <1>
        val.originalFilename?.toLowerCase()?.endsWith(extension)
      }
    }   }

and the GSP code is

<div class="input-group">
                <input type="text" class="form-control" readonly placeholder="${message(code:'info.uploadModal.language.placeholder.file', default:'Please select a document')}" id="bulkUploadDocumentInfo"/>
                <label class="input-group-addon btn btn-default" for="bulkUploadDocument">
                  <input type="file" id="bulkUploadDocument" name="infoMasterFile" style="display:none;" data-validate="maxFileSizeMB(5)" onchange="$('#bulkUploadDocumentInfo').val(this.files[0].name);">
                  <g:message code="info.uploadModal.language.label.searchFile" default="Add New File" />
               </label>
</div>
  • What does `val.originalFilename`, `val.empty` evaluate to when the file is there but less than 100kb? – Jeff Scott Brown Mar 18 '22 at 18:50
  • When the file is less than 100kn then the MultipartFile object is null, when its greater than 100kb then it has some value. – Hamza Riaz Mar 20 '22 at 07:36
  • "When the file is less than 100kn then the MultipartFile object is null, when its greater than 100kb then it has some value." - That is interesting. If you file an issue at https://github.com/grails/grails-core/issues with a sample app we can investigate. I am sorry for the trouble and thank you for the feedback. – Jeff Scott Brown Mar 21 '22 at 13:50
  • Did you find the reason/a solution? – David Brown Jul 19 '22 at 15:46

0 Answers0