Media and file cleanup

Last updated on
30 August 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Depending upon how you manage media on your site, media and file entity address file cleanup in different ways. Watch #1399846: Make unused file 'cleanup' configurable for a core issue related to this.

Files added through file/add form

If a file is uploaded to a site via the upload form at file/add it will be marked as permanent and will never be deleted via core's file cleanup functionality. Even if you use a file that had been initially uploaded this way on a file field on a node and delete the node, the file will remain permanent in the file system.

However, you can use navigate to admin/content/file, select the file and in the Update Options select “Indicate that the selected files are temporary and should be removed during cron runs."

Media library - Media WYSIWYG module

If a file is uploaded via the media library button in the WYSIWYG, it will also be permanent, like above. Even if you delete the node, the file will remain in the Media library.

However, any file embedded via the media library button will record usage when you look at the usage tab of the file.

File field

If a file is uploaded via a file field on a content type and the node is deleted, if the file is not used anywhere else on the site, it is deleted immediately.

Other considerations

If you upload a file in the first step of the Add file form and realize that it’s not the right file and click the remove button, it is removed from the file system immediately.

If you upload a file and do not finish through creating the file “entity” by clicking save at the end of the multistep form, the file is marked as temporary, and it gets deleted on a cron run if the file is older than six hours.

Help improve this page

Page status: No known problems

You can: