James Salavia James Salavia - 3 months ago 21
AngularJS Question

How i can restrict some file formats to be upload?

I am using angular file upload (nv-file-select) to upload file, now my question is how can i restrict some file formats so that user can only see files with doc/docx and xls/xlsx format.

<input type="file" nv-file-select uploader="vm.uploader"
name="uploadFile"
id="file1"
ng-model="vm.fileInfo.filename"
ng-click="vm.onFileClick()" / >


Please help me!

Answer

Yeah it's very simple, you can use 'accept' property of nv-file-select.

So your modified code will be like this:

<input type="file" nv-file-select uploader="vm.uploader"
            name="uploadFile"
            id="file1"
            ng-model="vm.fileInfo.filename"
            accept=".doc, .docx, .xls, .xlsx"
            ng-click="vm.onFileClick()" / >

You can put n number of files inside 'accept' method to show files with those extensions only.