# Cleaning up uploads and purging uploads from S3

**URL:** https://meta.discourse.org/t/cleaning-up-uploads-and-purging-uploads-from-s3/248343
**Category:** Site Management
**Tags:** reference, file-management
**Created:** [December 9, 2022, 1:26am UTC](https://meta.discourse.org/t/cleaning-up-uploads-and-purging-uploads-from-s3/248343 "2022-12-09T01:26:48Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [December 9, 2022, 1:26am UTC](https://meta.discourse.org/t/cleaning-up-uploads-and-purging-uploads-from-s3/248343/1 "2022-12-09T01:26:49Z")

</div>

> 🔖 This is a reference guide describing how orphaned and deleted uploads are automatically purged from a Discourse site. This guide applies to both self-hosted and hosted Discourse sites.
> 
> 🙋 Required user level: Administrator

Have you ever wondered what happens to files and images that were uploaded to a Discourse site but are no longer referenced, or how to remove uploads from a site? You’re in the right place!

You may need to delete files and images that are uploaded to Discourse that are no longer reference. There isn’t a built-in way to do this from the user interface, however, Discourse does have an automatic Sidekiq job scheduled to remove orphaned and deleted uploads called `clean up uploads`.

## Orphaned and deleted uploads

> ℹ Orphaned uploads are files that have been uploaded to a Discourse site but are no longer referenced. An upload is considered orphaned **if and only if** it’s not referenced:

- In the latest version of a post
- In a draft
- In a queued post
- In a site setting (e.g. logo, favicon)
- In a custom emoji
- In a theme
- In a user avatar/background/card image
- In a category logo/background image
- In a badge image
- In a group flair image

> ℹ Uploads are considered “deleted” when the topic/post they are contained within is deleted.

## Cleaning up uploads

To fully remove an upload from Discourse, you’ll have to do one of the following:

- Force the upload to become orphaned by removing any reference to the upload. This can be done by editing the upload link out of the post that it’s in, or any other places the upload may be referenced.
- Delete any and all topics/posts containing the upload, causing the upload to be considered as “deleted”. Note that you need to remove the image from the post before deleting the post to orphan it.

All orphaned unreferenced uploads and deleted uploads will then be removed from storage (after a grace period) once the `clean up uploads` job runs.

## Site settings

The following site settings are available at `example.discourse.com/admin/site_settings/category/files` for modifying how Discourse automatically purges uploads.

- `clean up uploads`: default true
- `clean orphan uploads grace period hours`: default 48
- `purge deleted uploads grace period days`: default 30

 ![Site settings for cleaning up uploads](https://global.discourse-cdn.com/meta/original/4X/2/4/7/247e335c18f0cdfcdd349796a8ccca08da077e6f.png)

The `clean up uploads` setting can be used to enable or disable the automatic deletion of orphaned unreferenced uploads. The `clean orphan uploads grace period hours` setting controls how long after a detected orphaned upload is purged. The `purge deleted uploads grace period days` setting controls how long tombstoned (deleted) uploads are retained before being permanently removed — this is handled by a separate `purge deleted uploads` scheduled job.

Additional details about the `clean up uploads` job are available in the [clean\_up\_uploads.rb file on GitHub](https://github.com/discourse/discourse/blob/main/app/jobs/scheduled/clean_up_uploads.rb).

## Purging S3 uploads

> ⚠ The following section is only applicable to self-hosted Discourse sites.

> ℹ If you are currently hosted on our [Enterprise Plan](https://www.discourse.org/pricing), please reach out to [team@discourse.org](mailto:team@discourse.org) if you have any questions about deleting uploads from your S3 storage.

Cleaning up orphan and deleted uploads works similarly for both local and S3 storages. The only difference between the local storage and S3 storages is that the cleanup of the S3 uploads is automatically handled by S3 via a [tombstone policy](https://github.com/discourse/discourse/blob/main/lib/s3_helper.rb). See [Managing your storage lifecycle](http://docs.aws.amazon.com/AmazonS3/latest/dev/object-lifecycle-mgmt.html) for additional details about how this is handled on S3.

By default, the `clean up uploads` job includes S3 uploads. However, if you would like to disable this feature, you can uncheck the `s3 configure tombstone policy` site setting.

 ![S3 configure tombstone policy setting](https://global.discourse-cdn.com/meta/original/4X/5/b/a/5ba9dd09ee5df919ba3289db93a25208d826e4a4.png)

> Last edited by @hugh 2024-07-26T01:29:25Z
> 
> > **Check document**
> >
> > Perform check on document:

---

_[View the full topic](https://meta.discourse.org/t/cleaning-up-uploads-and-purging-uploads-from-s3/248343)._
