Type:files for images

Hiya,

I’m trying to build something in my Kirby 3 project similar to Kirby 2’s type:image Basically a files type, but not multiple, and with a scope limit to images. Also it would be nice to restrict sizes and image types.

Following the reference, here’s what I have right now…

label: Image
type: files
multiple: false
query: page.images

This seems like it should work, but when I try to add an image to a field with that setting, I get the message

The files query does not seem to be correct

I don’t get that error if I remove the query line, except then I can put whatever file I want in that field.

This seems like an error in the files filed itself?

I also saw this line in the reference…

image array image settings for each item

Except I don’t get where I should look for those settings.

I dont think it quites work like that. Off the top of my head, try this:

type: files
max: 1
query: page.images

You can limit the size accepted, and the files accepted by mime type, via a file blueprint. See here.

Multiple: false turns off the ability to pick more that one at once in the popup. Max one means you can only set 1 image in the field.

In other words if multiple is on (the default), but max is set to 5 and you pick 8 images, it should warn you.

1 Like

No, multiple: false is a correct setting, it means max: 1

See album.yml Starterkit.

    fields:
      cover:
        type: files
        multiple: false

So what happens if you set multiple false and max to say, 6? Which one cancels out the other?

I’d say multiple: false means max: 1, no matter what you set max too.

@AhoyLemon What Kirby version are you using?

@texnixe 3.1.4

Hm, that’s strange, can you test if you get the same issue in a fresh Starterkit, modify the album.yml blueprint and add the same query. It works without issues for me in a fresh kit.

As regards limiting the files that are selectable, you can filter your files, e.g. by extension and file size:

query: page.images.filterBy("extension", "jpg").filterBy("filezize", "<=", "50000")

Or you limit file size right from the beginning via a file blueprint with a accept setting in your file upload section.

1 Like

Oh! I just realized where my mistake was there.

The specific field I was working on in my OP was the sitewide OpenGraph image, so I was working in site.yml, which then means that any page query isn’t going to work.

Refactored some stuff, and @texnixe’s query works perfectly! Thanks.

In site.yml you can do something like this:

query: site.find("somepage").images
1 Like

is filterBy('width', 1600) possible? I’d like to be able to set up specific dimensions for a couple of these fields.

Yes, that’s possible.