Programmatically generate image file in media folder after upload

I need to automatically generate images in the media folder after they have been uploaded. I’ve noticed that after the image is being uploaded only a thumbnail version is created in the media folder. I’ve tried wiring up a hook in config.php like this:

'hooks' => [
      'file.create:after' => function ($newfile) {
          $newfile->publish();
      }
    ]

The hook seems to work but the $newfile seems to be null. I am receving following error in the kirby panel:

Call to a member function publish() on null

The parameter has to be $file not $newfile.

1 Like

Works! I accidentally took the $newFile from the file.update.after hook. Thanks!!! Works like charm!

So, just to be sure the code needs to be this?

 'hooks' => [
    'file.create:after' => function ($file) {
      $file->publish();
    },
  ]

If I use this, the media is not being generated in the media folder…

Code is fine and files should be published in the media folder.

Hm, than I maybe need to do some debugging. Thanks.