Plugin: Link upload to product #2262
Ryeori
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Note
Because im a mobile developer not a front/back end developer and im not that familiar with typescript, this script should be wrapped with plugin according to payload cms documentation, here is my attempt to make it plugin and uplaoad to npm, it wont run so you can take it and make it work.
About this almost-plugin
Hello there, so im creating a ecommerce website with payload as backend and i aint found a way to somehow rename upload to match product id/ title and i've created a small script to rename uploads in collections (like Products collection and product have Preview upload field).
It will rename uploads to match this pattern:
Prefix - could be a product id or title, or any other identifying thing to work with.
Suffix - for my example i've used uuid v4, but you can generate whatever you want
File extension - file current extension
Usage
here is the instructions for it
Copy code gist from below to your project
Code gist here
Call it your upload filed after cahnge hook
And here it is, after you save your product it will automatically rename all provided uploads and sizes
Faq
1) Will it change other images sizes?
Yes, it will change other image sizes as well.
2) Can i provide multiple images for example if i have a other product images
Yes you can provide more, just add their's upload id into currentUploadsarray
Beta Was this translation helpful? Give feedback.
All reactions