Sync file upload folder with query source

Hello,

I’d like image uploads to end up in the same folder that’s given in the query option, but they are always stored in the folder of the content file.
The uploads property doesn’t seem to do the trick for type: files:

# /sections/guides-media.yml
type: files
query: site.find("guides").images
uploads:
  parent: site.find("guides")

Is there another property/setting that’s applicable to file/image fields to set the target upload folder?

The above snippet is part of a shared (sections) file which works fine for selecting images from a central location. Our users now need to go to the dedicated “central image library page”, upload their images and then pick them in the sub-page – which can be tedious.

For reasons, we need a couple of these dedicated upload sections where images can then be reused by any of the respective sub pages. I have prepared a bunch of these shared blueprints and while picking images from targeted folders works as intended, the upload button is virtually useless as files (by default) end up in the “wrong” location.

Related to that: how can I prevent the “upload file” button appearing, since uploads must then be prevented from within these specific page types, basically turning a files section into a “read only” mode.

Thanks.

Is it a field or a section now? The syntax is different for each, please see documentation.

The code defines a type:files as depicted and is loaded via extends into one section of a page blueprint for one of the sub-pages, hence a “shared (sections) file”. I added the file name as a comment to the OP.

# /pages/guide.yml
tabs:
  media:
    label: Mediapool
    sections:
      images:
        extends: sections/guides-media
      documents:
        extends: sections/guides-documents

I looked at the documentation for “Files section” and “Files” field but couldn’t find an answer, that’s why I’m here. uploads was mentioned in an old forum post by Bastian where he also said it’s “undocumented” (at that time). I thought I give it a try.

In any case, I need the ability to define a target upload folder for files no matter if they’ll show up in a section or a stand alone field.

It’s easier to manage images with other tools if they’re located in one spot and not scattered all over the place in a bunch of sub folders. That’s a bizarre concept in Kirby anyway I haven’t seen in other CMS. I understand the reasoning but over the years it turned out to be more inconvenient than not.

Thanks for any hints regarding the upload target folder.
I can also write some PHP code if need be, but I’d need a nudge to find the right API for the job.

So these are files sections, not files fields. Which means that there is no uploads option, but you need to define a parent prop. And this is all documented: Files section | Kirby CMS

I already said that upload was just a hunch as it sounds closest to what I need : an option to control the UPLOAD TARGET for files.

As expected parent didn’t work:

Sets the query to a parent to find items for the list

I tried parent in many ways before in both fields and sections to no avail.
There’s also no mention of parent setting an upload target for new files and in fact it doesn’t. New files end up in the same folder as the content file.

# /sections/guides-media.yml
type: files
query: site.find("guides").images
parent: site.find("guides")

If you have a working example then please show me the code, otherwise please refrain from pointing me to the manual when there is clearly no solution, explanation or sample provided that answers the question I have. It’s not that I haven’t read the docs or searched the forum.

I remember there was a cookbook post for a custom field that also dealt with uploads. Maybe that’s of any help if I find it.

Thank you so far.


So these are files sections, not files fields.

So? They both do pretty much the same thing. I don’t understand why there must be such a big distinction to make matters more complicated. There are tons of post regarding files and blueprint syntax and parameters so something must be broken that so many people keep asking questions about files for years …

  • Essentially both "files"flavours can find and show images (among other things) in one or the other way - but that’s merily cosmetics.
  • Both can have a query or parent to define another folder than the current content folder.
  • Both allow uploads.

If one “files” thing would have the option to change the upload target so should the other. Apparently neither has this feature unlike that editor field Bastian mentioned in that ancient post.

Have a nice time.

sections:
  files:
    type: files
    parent: site.find('uploads') #upload to a page called uploads

This is a files section. It has a parent option to define the upload target. This example definitely works.

On a side note, I don’t think the tone in your last post is appropriate.

A files section and a files field serve different purposes, yes, they share the option to upload files, and the different syntax required to define the upload target may be a bit unfortunate. However, the upload option was added to the files field at a later point, before that, we only had the files section to upload files.

Sorry to say, but it’s definitely NOT working. Neither for sections, nor for a field.
Despite the information in "Destination and template which is the only mention of a target(destination folder and it applies to the Files Field.
Maybe it works for site like in the sample but not for a statement such as site.find("whatever").

I do use it with sections and the Fields Section page has no information whatsoever that parent might also set the upload destination. If I have to take information from the Field documentation into account to understand the inner workings of the Sections then why make such a big fuzz about how different they are and require different “unfortunate” syntax?

I’m on Kirby 4.3 and file uploads always end up in the (sub-)folder of the content file. End of.

./content
  ./1_guides  <-- expected target: site.find('guides')
    ./1_some-guide  <-- the location doing the upload
      guide.txt
      uploaded-image.jpg  <-- wrong folder
  guides.txt
  ..                      <-- file should end up here

On a side note, I don’t think the tone in your last post is appropriate.

maybe, but nor was the condescending tone by moonwalk who replied like I was a lazy idiot.

Have nice weekend.

Please do the following in a fresh 4.3.0 Starterkit:

  1. In note.yml, add a new section before the meta fields section:
      filestest:
        type: files
        parent: site.find('notes')
        query: site.find('notes').files

And check where the files end up. I know this works, I have tested that is works. Maybe it’s something else in your code interfering.