Accept mime type on specific fields

Hello,

I think I miss somethig here about the files upload restriction.

I see that we can restrict the files upload to some mime-type but according to the doc https://getkirby.com/docs/reference/panel/blueprints/file#accept it seem to cover all files from all fields ?

How to tell my gallery field to accept only image (png, jpg, jpeg), and tell another field to accept only MP4 video ?

Thanks!

In the files blueprint for the images, you can put:

accept: image/*

And you can make another files blueprint for videos

accept: video/mp4

Via a file template, where you can set the accept property.

I tried and that don’t work directly on the blueprint for a field with a files type.

For what I understand, this should work or I totally miss everything and need to sleep a little :smile: ?

fields:
  gallery:
    label: Vidéos
    type: files
    template: gallery
      accept: video/mp4
    min: 1
    required: true

No, the accept options goes into the file blueprint.

If your file blueprint is called gallery.yml, in gallery.yml put

Title: Gallery template
accept: video/mp4

And the upload template syntax:

fields:
  gallery:
    label: Vidéos
    type: files
    uploads: gallery
    min: 1
    required: true

Or if you want to set an explicit page to upload to (other then the current page)

fields:
  gallery:
    label: Vidéos
    type: files
    uploads: 
      parent: site.find('mediapage')
      template: gallery
    min: 1
    required: true

Get some sleep sounds like a great idea.

1 Like

Thanks for your help @texnixe. Yep I might go to sleep now! It’s was finally simple… But maybe it need an explaination on the Kirby doc on how to do it ? Or in the Cookbook.

Hm, it’s actually in the links I posted above, where would you expect this to be explained? Or do you mean the step from the field to the accept option in the blueprint? Yes, I guess we can make this clearer.

Sorry to wake this thread up again. I am struggling with disallowing only tiffs from upload. This is my complete file blueprint “work-image.yml”:

title: Work Image

accept:
  mime: image/jpeg, image/png, image/webp, image/gif
  minwidth: 500
  minheight: 500

fields:
  alt:
    label: Work Title
    type: text
    help: Google likes this, so try to fill it out as often as possible.

Even though it should be correct my client can still upload tiffs which cant be properly displayed (and are sometimes even like 16bit files).

Could you provide the blueprint where you are assigning this work-image.yml to your section/field?