# Sync file upload folder with query source

**URL:** <https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237>\
**Category:** Questions\
**Tags:** v4\
**Created:** [August 13, 2024, 6:22am UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237 "2024-08-13T06:22:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![WebMechanic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/webmechanic/32/1462_2.png) [@WebMechanic](https://forum.getkirby.com/u/WebMechanic)\
**Post date:** [August 13, 2024, 6:22am UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/1 "2024-08-13T06:22:16Z")

</div>

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`:

```auto
# /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.

---

<div class="post-metadata">

**Author:** ![moonwalk](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@moonwalk](https://forum.getkirby.com/u/moonwalk)\
**Post date:** [August 13, 2024, 6:38am UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/2 "2024-08-13T06:38:53Z")

</div>

> [@WebMechanic](#):
>
> that’s applicable to file/image fields

> [@WebMechanic](#):
>
> The above snippet is part of a shared (sections) file

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

---

<div class="post-metadata">

**Author:** ![WebMechanic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/webmechanic/32/1462_2.png) [@WebMechanic](https://forum.getkirby.com/u/WebMechanic)\
**Post date:** [August 13, 2024, 2:52pm UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/3 "2024-08-13T14:52:43Z")

</div>

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.

```auto
# /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.

---

<div class="post-metadata">

**Author:** ![moonwalk](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@moonwalk](https://forum.getkirby.com/u/moonwalk)\
**Post date:** [August 13, 2024, 3:26pm UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/4 "2024-08-13T15:26:27Z")

</div>

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](https://getkirby.com/docs/reference/panel/sections/files#section-properties)

---

<div class="post-metadata">

**Author:** ![WebMechanic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/webmechanic/32/1462_2.png) [@WebMechanic](https://forum.getkirby.com/u/WebMechanic)\
**Post date:** [August 15, 2024, 7:22pm UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/5 "2024-08-15T19:22:09Z")

</div>

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.

```auto
# /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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 15, 2024, 8:00pm UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/6 "2024-08-15T20:00:03Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![WebMechanic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/webmechanic/32/1462_2.png) [@WebMechanic](https://forum.getkirby.com/u/WebMechanic)\
**Post date:** [August 16, 2024, 5:03pm UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/7 "2024-08-16T17:03:06Z")

</div>

Sorry to say, but it’s definitely NOT working. Neither for sections, nor for a field.  
Despite the information in "[Destination and template](https://getkirby.com/docs/reference/panel/fields/files#upload-options__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.

```auto
./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.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 16, 2024, 5:15pm UTC](https://forum.getkirby.com/t/sync-file-upload-folder-with-query-source/32237/8 "2024-08-16T17:15:43Z")

</div>

Please do the following in a fresh 4.3.0 Starterkit:

1. In note.yml, add a new section before the meta fields section:

```auto
      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.
