简体   繁体   中英

How to filter the file types in primeng p-fileupload component

I am trying to filter the file dialogue window using p-fileUpload from primeng. I saw an example to to filter images as image/* and it works but i want ti filter for excel files. I tried file/excel, file/*.xls etc, but no help. Need help.

Try below inputs with accept property in p-fileUpload in Angular

  1. Image filter
    accept="image/*" [accepts all image file types]
    accept="image/*.jpeg" [accepts only JPEG image file types]

  2. File filter
    accept="application/msexcel" [accepts only xls file types]
    accept=".xlsm,application/msexcel" [accepts only xls & xlsm file types]
    accept="application/msmsword" [accepts only word file types]

我们可以像这样按所需类型过滤

accept=".xlsx,.pdf,.csv,.xls"

.html

<p-fileUpload accept="{{acceptedFiles}}" invalidFileTypeMessageDetail="Sólo se permiten ficheros {{acceptedFiles}}"></p-fileUpload>

.ts

 acceptedFiles: string = ".pdf, .jpg, .png, .doc, .docx, .xls, .xlsx, .csv";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM