Modify file before it's uploaded

default discord avatar
sam
8 months ago
6

I want to run some custom transforms on a file before it's uploaded.



Looking at the arguments received in the beforeChange hook, I don't think it's possible to handle it there. Is there a way to do this?



bump

  • default discord avatar
    Alessio 🍣
    8 months ago

    Just a thought: maybe it might work with some kind of beforeChange hook. Because you can actually get all "incoming files" from it. Something like that is being used here:

    https://github.com/payloadcms/plugin-cloud/blob/main/src/hooks/beforeChange.ts#L21


    Maybe that helps figure something out!



    Might be completely wrong there though

    :robotshrug:

    I don't know the exact solution to this

  • default discord avatar
    sam
    8 months ago

    I ended up going that route but was hoping there was a cleaner/proper way. I can access the files but by the time that beforeChange runs, they are already written to disk unfortunately.



    My next step is to disable the local storage and write to the disk myself with the modified files 🤞

  • default discord avatar
    Alessio 🍣
    8 months ago

    that sounds like a good plan tbh!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.