Unfortunately I never really bothered to learn how to code a proper hook and wanted to ask you if someone was interested in coding a file.create:after hook.
A small client of mine wishes to be able to upload videos to her website via the Kirby panel. No big deal there, however , after uploading a video to the Kirby panel, the same video should upload to her JWPlayer-account. JWPlayer is a streaming platform similar to Vimeo . They provide an API especially for that kind of function.
The reason for that is, she doesn’t want to have multiple logins to upload videos but only the Kirby panel login and not having to login to the JWPlayer’s dashboard.
The API call is to simply provide a video URL to the JWPlayer API via PHP and they automatically fetch the video from the provided URL.
They call this API call PHP URL fetch . So the hook’s function would be to make the API call via PHP to the JWPlayer’s API after a video has been uploaded via the native files-section – the JWPlayer’s API then automatically fetches the Video and returns the new Video-URL.
The newly returned URL would then be stored as a simple string inside a field along a sorting number (like in the native files section). It would not need to output anything else than the URLs and sorting number because embedding the videos to the actual website would be done on the frontend.
Unfortunately, this task is not within my current skill range.
Extending core sections is not very straight-forward unfortunately (at least for me). However if I understand your use case correctly you could simply use a file.create:after hook and put your API call there.
By using a file blueprint for this files section you can check for it in the hook and only upload files uploaded to this one specific files section.
Is the success message critical? Maybe it could work in the other direction: The hook waits until the API has confirmed the upload. If there was an error, that error is passed back to the Panel from the hook and if there wasn’t, it all succeeds like normal.
Yeah that would be fine as well, however I’m not sure yet if the hook can wait for the API callback.
@texnixe suggested to use sleep(X) but I don’t know if sleep uses a hardcoded amount of seconds or not. Like if sleep(10) is used but the upload fails after 20 seconds the hook won’t know. Or am I misunderstanding?