Hi, This is more of a question. The October\Rain\Database\Attach\File Model has these two methods
getDiskName() and getPartitionDirectory() that generate a custom file path and name for uploaded objects.
I'd like to create a BaseFileModel and extend this class to overwrite these methods, something like
{model_name}/{attribute_name}/{model_id}/{file_name}
uploads/public/user/avatar/1/my_avatar.jpg
My question is why October chose this naming convention for attachments, Is there any reason I should avoid what I am trying to do ?
Thank you
434
I suppose it is for uniform file distribution (to keep number of files per directory relatively small even for large amount of files).
A stored file name itself should be a hash of a real file name (due to uniformity of hashes). In this case when you have for example, 10000 of files, they will be distributed into multiple directories with only a few files per directory. You won't end up with thousands of files in one dir and no files in another.
Here's a nice question explaining the problem: https://serverfault.com/questions/95444/storing-a-million-images-in-the-filesystem
And following your question - you can use your own rules for file naming if they they fit you. It's not a requirement, it's recommendation made by default.
Makes sense. Thank you
Most helpful comment
I suppose it is for uniform file distribution (to keep number of files per directory relatively small even for large amount of files).
A stored file name itself should be a hash of a real file name (due to uniformity of hashes). In this case when you have for example, 10000 of files, they will be distributed into multiple directories with only a few files per directory. You won't end up with thousands of files in one dir and no files in another.
Here's a nice question explaining the problem: https://serverfault.com/questions/95444/storing-a-million-images-in-the-filesystem
And following your question - you can use your own rules for file naming if they they fit you. It's not a requirement, it's recommendation made by default.