Files should be uploaded to per year/month directories by default

Created on 5 November 2013, about 11 years ago
Updated 10 July 2023, over 1 year ago

Problem/Motivation

Drupal will upload files into one directory by default. Users can affect this by changing configuration of file/image fields, but real-world experience shows that they don't. Uploading thousands or millions of files into one directory is a very bad idea, which can have performance implications too. There are reports of sites going down just as a result of this issue.

Proposed resolution

Let's change default location configuration variable in file/image fields. This variable is currently empty, which results in all files being uploaded in a root folder (usually public://). Since use of tokens is supported we can provide configuration that will dynamically adapt for different fields.

[field-storage:name]/[date:custom:Y]-[date:custom:m] was preferred but couldn't make it in time for RC1 so we've decided to simplify the patch to minimize the disruption and file πŸ“Œ Uploading files should have more robust default tokens Closed: outdated instead.

We're now going with [date:custom:Y]-[date:custom:m] only for all fields. On top of that we've decided to upload user avatars under pictures/[date:custom:Y]-[date:custom:m] and to remove file_directory: field/image completely from field.field.user.user.user_picture.yml since it would be duplicating what the default is anyway.

Remaining tasks

User interface changes

Site builders now see the default tokens in the File directory field for files/images. This can still be completely customized to suite their needs.

API changes

None.

Original issue summary by @meba β†’

It is a well known fact that if you upload thousands of files into a single directory you will have performance issues on certain systems such as Cloud systems using GlusterFS, NFS or other shared filesystems or simply slow hard drives. The reason being that list operations on that single directory take too much overhead over network.

The solution typically is to ensure there is no more than a couple of thousands of files in a single directory in your files/. This can be easily achieved through dividing directories by date:

30/12/2013/file.jpg
29/12/2013/file2.jpg

https://drupal.org/project/filefield_paths provides this functionality but many people do not install it when they create their website and migration is complicated.

I propose that we automatically add date based tokens to all file system paths in Drupal core and allow modules such as FileField Paths to override these tokens to provide advanced functionality.

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ“Œ Task
Status

Fixed

Version

7.0 ⚰️

Component
File systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¨πŸ‡ΏCzech Republic meba

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada jigarius MontrΓ©al

    I wish the files were uploaded by default to a directory like "YYYY/MM" instead of "YYYY-MM". I'll see if I can find an open issue for that.

Production build 0.71.5 2024