Here is how to use UUIDs as directory names instead of regular IDs #1921
-
tl;drMake your own implementation of Hi there, I’ve just upgraded from You may know that version 8 automatically generates a UUID for each media. This is really useful if, for example, you want to prevent users to tweak URLs to discover (or to scrape) all of your images. But, by default, MediaLibrary will put each media (and its conversions) in a directory named with the ID (primary key) of the media. If you want to use UUIDs instead, you have to add a bit of customization. Here is how to do it. How MediaLibrary decides where to store filesIn order to determine where to store and retrieve your files, the package uses a class called In this file, we can see that the ID (the primary key) of each media model is used to name each media directory: /*
* Get a unique base path for the given media.
*/
protected function getBasePath(Media $media): string
{
return $media->getKey();
} The But we cannot update that file directly, obviously, because it is in the Create a custom
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Thanks! To make it work right now instead of implementing "PathGenerator" you should extend "DefaultPathGenerator". |
Beta Was this translation helpful? Give feedback.
-
Do not forget to update the config as well:
|
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
-
I'm using S3 - it seems that updating the directory structure configuration works OK, original file upload generates the structure correctly, getTemporaryUrl() method works and I can access the file, but when it comes to generating responsive images via a job, it fails because it tries to reach the original file via the media ID (not UUID). Did I do something wrong?
Edit: Clearing cache and restarting workers seems to have fixed it. |
Beta Was this translation helpful? Give feedback.
Thanks!