How to restrict the file type for an upload field?

Hi all,

for a current project, there’s the rather basic requirement to restrict the file type upload to .mp3 for a particular category of entries. My attempts were met by unexpected resistance by Kirby’s structure. Initially, I expected this to be a simple property of the files field.

Here’s the blueprint I currently use:

title: Entry
preset: page
    label: Text
    type: textarea
    size: large
    uploads: false
    required: true
      - bold
      - italic
      - '|'
      - link
      - '|'
      - ul
      - ol
    type: fields
        label: Published on
        type: date
        time: true
        default: now
        label: Audio
        type: files
        multiple: false
        label: PDF
        type: files
        multiple: false

The state of my research thus far:

As you can see from the blueprint above, I’m using a default page preset. Ideally, the audio field should restrict to .mp3 and the PDF field to .pdf extensions.

I’m confused as to how to implement the file type restriction in the above blueprint. Is this even possible or does the current Kirby structure require me to completely rewrite the blueprint to use sections? If so, how?

You have to set the uploads property of the files field to apply a file template/blueprint, as documented in the files field reference: Files | Kirby CMS

In that file blueprint, you set the accept option to limit what you can upload to this field.

You also need to limit your query to this file template.

Fantastic, that appears to work. Thank you very much! I’ve had all the information on blueprints and whatnot but not how to apply it. It was right there, I must have overlooked it. I suspected that it just couldn’t be complicated.