Search code examples
ng-file-upload

How to show the file size which failed to upload in ng-file-upload?


The ng-file-upload documentation shows samples of usage. The first sample fiddle displays a validation message for file size:

<input type="file" ngf-select ng-model="picFile" name="file"    
             accept="image/*" ngf-max-size="2MB" required>
      <i ng-show="myForm.file.$error.required">*required</i><br>
      <i ng-show="myForm.file.$error.maxSize">File too large 
          {{picFile.size / 1000000|number:1}}MB: max 2M</i>

However, when I run the fiddle and upload a file larger than 2M, the validation message says:

File too large MB: max 2M

So the expression {{picFile.size / 1000000|number:1}} is absent from the message. It looks like picFile.size is not set. Is there a way to show the size?


Solution

  • Updated the sample page: http://jsfiddle.net/danialfarid/maqbzv15/544/

    You can use ngf-model-invalid="errorFiles" and then get the invalid file size by errorFiles[0].size.