October: File Attachments name convention

Created on 15 Mar 2018  路  2Comments  路  Source: octobercms/october

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

October build

434

Question

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.

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m49n picture m49n  路  3Comments

dunets picture dunets  路  3Comments

LukeTowers picture LukeTowers  路  3Comments

jvanremoortere picture jvanremoortere  路  3Comments

sozonovalexey picture sozonovalexey  路  3Comments