I have a 2 collections first is for products with preview image field (upload type) in it as well as field for other images of the product, second one to store those images -productMediaCollection
I wanted on image upload (for example fromproducts
collection) to change the name or/and file path of it to fit product title like:
or at least to change the name to something like this:
So is there a way to change default uploading name for example viabeforeValidate
hook, because i dont quite understand how to do it?
Or maybe it possible to provide some function tostaticDir
to make it conditional?
Thank for answers
There is a Github discussion on this topic:https://github.com/payloadcms/payload/discussions/1153
You should be able to handle it in a
similar to marked answer.
Thank, this solution might work, but if i create hook onproductMediaCollection
then i cant have an access to information about product from which i created a media 😦
so i cant provide a product title or something like that into hook
So i media collection hook dont knows from where it was edited last time or something like that