Querying all site images in image.yml blueprint

So I have a website with lots of images. And sometimes images are uploaded for a project, but then a news post would re-use that image. Or another unrelated page would re-use an image that was uploaded in a news post.

I was thinking a solution could be that for all images, a new image can be uploaded, or one one selected that is already uploaded.

I have this blueprint:

site/files/image.yml

# Each file blueprint must have a title, the title may be different from the file name
title: Image

# Like page blueprints, file blueprints can define a layout with tabs, columns, sections and fields
# File blueprints define what sort of information should get stored in a file's meta data file
# In addition to the fields defined in this example blueprint, you can also set what type of file is acceptable
# when this blueprint is used, which allows you to control what users can upload.
# More about file blueprints: https://getkirby.com/docs/reference/panel/blueprints/file

query: site.index.images

accept: 
  type: image

columns:
  - width: 1/2
    sections:
      content:
        type: fields
        fields:
          caption:
            label: Opschrift
            type: textarea
            size: medium
          alt:
            label: Alt text (beschrijving van de afbeelding) 
            type: text
  - width: 1/2
    sections:
      meta:
        type: fields
        fields:
          link:
            label: Link
            type: text
            icon: url

However I do not seem to get the option to search for an image when making a post or page with an image.

Is there a way to achieve what I’m after? Or is it a very dumb idea to always query all the images on a website every time you want to add one? (I can image that there may be performance issues.)

This query does not belong there, it doesn’t have any effect. You need to query images in a files section or files field.

Other than that, I’d go for either of these two options

  1. upload files to a central files folder from which all pages query their images as needed
  2. upload files to where they are used, no matter if this results in duplicate uploads of the same image to multiple folders.

With thousands of images, option 1 might run into performance issues, but less than if you query all pages for all used images.

Do I understand correctly that this means that it’s not possible to add a query in a files blueprint?

This sounds like it makes sense. But is there a way to do this when a site already has lots of images uploaded in the folders for the pages that they are used on? Also, just for reference, the website I’m working on has around 1000 images.

Exactly, where did you find that suggested? This is what you can have in your file blueprints: File blueprint | Kirby CMS

Yes, at least if use Kirby’s UUIDs, it should work if you move the files, then recreate the UUID cache, so that any references in files or other fields don’t break. But make a backup first before you try and test this.

If you use files sections in your pages, from which you fetch the files in the page template, this approach will not work, as then the files will be gone.