File attachments- Best way to integrate into custom app?

Hello, hope everyone is doing well.

I have been researching how to control file attachments in my custom doctype within a custom app. I would like to control the naming of the file and the folder the files end up in. I would like to use the Attach field but I don’t see any triggers that are usable in upload.js,,, or control.js.

I thought I would hijack the on_upload_complete from control.js. It works, I get the attachment but it is already named and stored.

  1. Is there a way to manipulate files on the file system after they are saved?
  2. Is there a better way to change the file name to be saved before the file is saved the first time? Using built-in functions…

I am aware I can write my own code to do all this but it would be nice if there where a before_save event triggered.

Thank you,

You can trigger before_save in File doctype (add a hook for that)

Add your triggers, but add them on the server side. Files can also be added via APIs