File picker that only allows to pick specific file types

I have a simple file blueprint that seems to work fine:

title: My PDF Upload

accept:
  extension: pdf

options:
  changeName: true
  replace: false
  delete: true

It only allows me to upload only PDF files, which is exactly what I want. However in the field itself, besides the “upload” option, users can also “select” a previously uploaded file. And the latter are not filtered by pdfs. Users can select basically anything.

How can I allow users to only pick specific file types in a field?

That’s done with the query option: Files | Kirby CMS

Using a query, you can filter your files by anything, e.g. by extension.

1 Like

I did try
query: page.files.template('myPDFTemplate')
but got the following error:

Your query must return a set of files

Same same with
page.files.filterBy('myPDFTemplate')

A complete example on how to do this would be much appreciated :pray:

Here’s what I’ve got so far:

myCustomField:
    label: My Custom Field
    type: files
    uploads: myPDFTemplate
    query: page.files.filterBy('myPDFTemplate')
    max: 1

Please don’t use camel case, stick with lower case letters for all filenames. The query will then work as expected.

Examples for queries can be found in the general guide: Query language | Kirby CMS

Thanks ternixe!

Unfortunately I was still not able to get it to work.

✓ Changed everything to lowercase
✓ Realised I’m on site level, not on page

uploads: mypdftemplate
query: site.files.template('mypdftemplate')

Upload works fine. But a click on “Select” says

No files to select

What am I missing this time? :see_no_evil:

Did you assign a template to the files during upload? You can also look this up in the .txt.
Can you also post the entire blueprint code? Maybe there is an error at another place.

1 Like

This was it! After uploading my files again everything worked as expected. Thanks! :blush:

1 Like