Permalinks for files

Hi,
is there a way to get permalinks for uploaded files in Kirby which stay stable, even when a new version of a file is uploaded? $file->url() seems to change if file modification timestamp changes.

Whats the use case? are you trying to use it with an external service or something?

You can overide the file url like this:

<?php

Kirby::plugin('hashandsalt/kirby-file', [
    'components' => [
        'file::url' => function (Kirby $kirby, $file) {
          $page = $file->parent();
          if (preg_match('/downloads\/|downloads$/', $page->uri()) > 0) {
            return $kirby->url() . '/content/' . $page->diruri() . '/' . $file->filename();
          } else {
            return $file->mediaurl();
          }
        }
    ]
]);

You will need to tweak the preg_match part to suit your project. The example above will return a content folder url (a permanent url) if the word downloads appears somewhere in the URL. Just change the condition to something that works for you.