I am using hooks to update some data when the user uploads a file.
One of the use-cases is that we want to generate a "preview-image" from the input data, upload it and attach it to the item.
https://docs.directus.io/extensions/hooks.html#creating-hooks
How can I access the API or create/save a directus file entry within the hooks?
You should be able to use the API normally within a hook. So you can use the "Create File" endpoint to upload the preview image, within a blocking
files.create.before
(in v9).https://github.com/directus/next/blob/main/docs/guides/extensions/api-hooks.md
That said, Directus will automatically create preview images using the thumbnailing system... so you shouldn't even have to build this custom.
https://docs.directus.io/guides/files.html#asset-middleware