Panel: How to redirect to file immediately after an upload?


I would like my clients to go to the file screen after uploading a file in the panel. This is because in my blueprint I have defined all images to have a caption, and I don’t want them to miss the place to set the caption.

Does anyone know how could i get this to happen?

There is a panel.file.upload hook, as described here:

This hook passes a $file object, which you can use along with go() to redirect the user to the editing page.

But keep in mind that it’s possible to upload multiple files at once. I’m not sure if the hook is fired after each upload or after all files are uploaded. This should be tested.

Hey Sam

Thanks, that was super useful.

I have added this to config.php, but I can’t even seem to get that to work:

kirby()->hook(‘panel.file.upload’, function($file) {

Do you know how might I find the Panel-address for $file? Something like $file->dir() . $file->filename()?

Thanks @flokosiol! Good to know. Would the hook on panel.file.upload be run once per file, in the case of multiple files, or do you think it returns an array of files? In that case I think I could check if it’s an array and in that case don’t redirect…

You can try this, it generates the right link, but I don’t think you can control the workflow like this:

kirby()->hook('panel.file.upload', function($file) {
  go($url . '/panel/pages/' . $file->page() . '/file/' . $file->filename() . '/edit');

Hey, thanks @texnixe — I just tried it but it didn’t work, is there something I need to do to ‘refresh’ the settings like restarting kirby in some way to clear a cache? I uploaded a file with that but it doesn’t seem to actually intercept the upload in any way :S (sorry if that is a stupid question)

Since the uploads are handled via AJAX you are only redirecting the response to the AJAX call. You can preview the response on the Network tab on Chrome’s Developer Tools.

1 Like

Thanks @pedroborges — I ended up solving this with a little bit of help text in the blueprint instead :slightly_smiling: