Files field query is invalid

I have a field like this in my site blueprint:

openGraphImage:
  type: files
  multiple: false
  query: page.images
  required: true
  translate: false

The query here triggers the following error in the panel:

Your query must return a set of files

However this query seems correct according to the Kirby docs.

What am I doing wrong?

You dont need the query at all, the default is to show all the files on the page. Unless…do you have other file types on the page and you just want to show images in it?

That’s the idea, I want to allow only images to be selected.

If you want to restrict the type of images that can be uploaded to the page via this field, you have set the upload property with a template that contains an accept property.

I want to restrict the type of files from this page that can be attached to this field in particular. The code I shared is taken from the docs (https://getkirby.com/docs/reference/panel/fields/files#querying-files__limit-the-set-to-images) but doesn’t work.

Should I open a bug in Kirby repo or Docs repo? I’m not sure which one is supposed to be correct.

I can’t reproduce your issue or only partly.

With the above file field setting, I can only select images, not documents etc.

You can, however, upload other files if you don’t restrict this in the uploads option by setting a files template and

 uploads: 
    template: files-upload

inside this template, set the accept property.

However, without this setting–and that’s probably a bug–while other files are not selectable, a file uploaded that is not an image is immediately selected without Kirby complaining.

I found the issue; I was querying page.images at the site level, it should have been site.images instead.

Thanks for your help!

1 Like