Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngf-pattern not working for ng-file-upload

I am trying to limit the file type to CSV in the ng-file-upload component but it isn't working - it still accepts all files.

I have tried both ngf-pattern="'*.csv'" and ngf-pattern="*.csv".

Code:

   <button class="btn btn-info" type="file" ngf-select="uploadFiles($file, $invalidFiles)"
                        ngf-pattern="'*.csv'" ngf-max-height="1000" ngf-max-size="1MB">
                    <i class="fa fa-upload"></i> {{'main.users.import.button' |translate}} </button>

Dependency:

  "ng-file-upload": "~10.0.2",
like image 942
Menelaos Avatar asked Dec 07 '15 07:12

Menelaos


2 Answers

Try to add the accept attribute too and remove the *:

<button class="btn btn-info" 
type="file" 
ngf-select="uploadFiles($file, $invalidFiles)" 
ngf-pattern="'.csv'" 
accept=".csv" 
ngf-max-height="1000" 
ngf-max-size="1MB">

EDIT: accept without single quotes

like image 174
michelem Avatar answered Oct 26 '22 00:10

michelem


<button id="select_resume_btn" class="btn btn-default" type="file" 
        ngf-select="uploadFiles($file, $invalidFiles)" 
        ngf-pattern="'.docx,.pdf'" 
        accept=".docx,.pdf" 
        ngf-max-size="5MB">Select Resume</button>

This worked for me !! Thanks @Michelem

like image 41
kads Avatar answered Oct 26 '22 00:10

kads