Copy Media Folder to Server

Hi, I’m aware that the media folder shouldn’t be copied to the server and that the hashed folders and thumbs are created dynamically.

Its just that both the GD and ImageMagick installations that are pre-installed on my shared-hosting server (Ionos) both don’t work with AVIF. For GD its disabled and for ImageMagick its not supported and they won’t update either of them. Therefore I’m now using the Janitor Plugin to generate all thumbs locally where ImageMagick can generate AVIFs.

Is it somehow possible to upload the media folder to the server and keep the urls intact, since the hashed folders are different between the local and server environment?

Many thanks in advance!
Best, Erik

You could replace the hash with something static, then it should work. You will loose automatic cache invalidation that way though.

Don’t you use Kirby as a CMS then or only locally and not on the server? Otherwise, if you add images on the server, the thumb won’t be generated either?

How about moving to another hosting provider?

Thanks for your fast reply!

You could replace the hash with something static, then it should work. You will loose automatic cache invalidation that way though.

This is actually what I did now. As far as I understand it, the hash is in part ‘generated’ by the modified date of the file and this date is different in the local environment and the server. I changed that part to be ‘generated’ by the filename. I changed some files in the kirby folder. It doesn’t feel right to do so, but I don’t know another way.

There is another thread (Adjusting the media hash generation) which led me to those files.
Idk whether its a good idea to share my code since its probably really bad, but it seems to work for me.

/kirby/src/cms/app.php

public function contentToken(object|null $model, string $value): string
{
	if ($model !== null) {
		return hash_hmac('sha1', $model->name(), 'foo');
	}

	return hash_hmac('sha1', $value, 'foo');
}

(I think $model might be the file object and $value might be some related data)

/kirby/src/cms/file.php

public function mediaHash(): string
{
	return $this->mediaToken() . '-' . '1';
}

(I left both ‘-’ and ‘1’, since the thumbs job of the janitor plugin has a regex to find all .jobs in the media folder and it searches for those types of characters. Otherwise there is no reason for leaving them there.)

Now the hashed folders are always the same, both locally and on the server. Which means that I can generate all thumbs locally and upload them to the server, which is of course not the most elegant way, but as I said, I somehow have issues with generating AVIF files on the server.

Don’t you use Kirby as a CMS then or only locally and not on the server? Otherwise, if you add images on the server, the thumb won’t be generated either?

I’m going to use Kirby as a CMS both locally and on the server. But the server will just be an exact mirror of the local version.

How about moving to another hosting provider?

Yes, you are right, maybe another hosting provider might be worth thinking about, or at least another plan where I can install my own instance of ImageMagick etc.

If you have any suggestions for a more thorough approach than the above, I’d be happy to hear about it! But thanks a lot already!

It’s a pretty bad idea to overwrite Kirby’s source files. Your changes will be undone with every update plus, if you are not 100% sure you know what you are doing, you might break the whole site.

$model refers to the current model, be it $file, $page, $site…

I’m not 100% sure how to best achieve that, one thing you can do is create a custom Kirby class that changes that contentToken method, so you can get rid of that auto generated token.

Remains the timestamp of the file modification time which might also become an issue.