# Query to get all (uploaded) files of a Kirby instance

**URL:** <https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547>\
**Category:** Questions\
**Tags:** v3\
**Created:** [December 28, 2020, 2:35pm UTC](https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547 "2020-12-28T14:35:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![renestalder](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/renestalder/32/10851_2.png) [@renestalder](https://forum.getkirby.com/u/renestalder)\
**Post date:** [December 28, 2020, 2:35pm UTC](https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547/1 "2020-12-28T14:35:29Z")

</div>

Is there one query to get all files ever uploaded to the Kirby instance, no matter they belong to `site` or any pages or subpages?

---

<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:** [December 28, 2020, 2:40pm UTC](https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547/2 "2020-12-28T14:40:46Z")

</div>

You should be able to get all files with

```auto
$site->index()->files()->add($site->files())

```

Note that calls to `$site->index()` should be used with care: [https://getkirby.com/docs/reference/objects/site/index#details](https://getkirby.com/docs/reference/objects/site/index#details)

---

<div class="post-metadata">

**Author:** ![renestalder](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/renestalder/32/10851_2.png) [@renestalder](https://forum.getkirby.com/u/renestalder)\
**Post date:** [December 28, 2020, 3:05pm UTC](https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547/3 "2020-12-28T15:05:28Z")

</div>

Nice, works like a charm (except that it seems that `add` does not work when the query is used in the kql plugin, but I find a way around that certainly).

Regarding the warning, do you know how the caching works in that regard? Is there a large hit when calling `site.index()` multiple times or will it return results from a cache?

As I only make one huge API request during static side generation, but which contains multiple queries.

---

<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:** [December 28, 2020, 3:59pm UTC](https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547/4 "2020-12-28T15:59:39Z")

</div>

If you don’t have a huge site, there is no reason to worry.

I have no idea if or how caching works in the KQL context…

It might make sense to set up a cache for this collection though, maybe in a plugin with some logic to purge the cache when needed.

---

<div class="post-metadata">

**Author:** ![renestalder](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/renestalder/32/10851_2.png) [@renestalder](https://forum.getkirby.com/u/renestalder)\
**Post date:** [December 28, 2020, 4:11pm UTC](https://forum.getkirby.com/t/query-to-get-all-uploaded-files-of-a-kirby-instance/20547/5 "2020-12-28T16:11:55Z")

</div>

Alright. Thank you very much for your prompt responses and your help. Very appreciated.
