# How to Delete Uploaded Files?

**URL:** https://meta.discourse.org/t/how-to-delete-uploaded-files/25001
**Category:** Support
**Created:** [9 februari 2015 om 07:53 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001 "2015-02-09T07:53:55Z")
**Posts on this page:** 9
**Page:** 2

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2 oktober 2020 om 09:52 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/22 "2020-10-02T09:52:31Z")

</div>

> [@anon47420739](#):
>
> So an image with an `upload` record that was never actually posted or was edited out of a comment would be deleted automatically. That correct?

That is correct.

> [@anon47420739](#):
>
> This doesn’t seem like it’s being “served”, it seems like it’s being uploaded. Is that not the case?

Can’t tell since you ninja edited your post which did not create a new revision. The first version of this post only has “edited.png”.

> [@anon47420739](#):
>
> - I deleted the link at the dropbox end and immediately it stopped being viewable in the post.

Which makes me think that you linked the image and did not upload it.

> [@anon47420739](#):
>
> there is no pencil - to test this:

Yes, because you edited your post too quickly. We have a grace period window of 300 seconds here in which if you make an edit, it won’t create a new version of the post.

> [@anon47420739](#):
>
> The behavior in point one runs counter to the post [here](https://community.signalusers.org/t/bug-no-full-screen-video-controls-in-4-70-5-android-11/16709), if you look through the first post edit history you can see a .gif.

If you look at the raw, you see that the images are merely links to dropbox

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/5/0555d55d244a3d351a04197434e94effa4a9c750.png)

Those were not uploaded. Just linked.

---

<div class="post-metadata">

### Author: ![anon47420739](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@anon47420739](https://meta.discourse.org/u/anon47420739)
#### Post date: [2 oktober 2020 om 10:16 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/23 "2020-10-02T10:16:11Z")

</div>

Thank you.

> [@zogstrip](#):
>
> Those were not uploaded. Just linked.

The underlying links have long been deleted - Shouldn’t that mean these .gif should seize appearing? Clicking “View Image” from the context menu takes me to a community.signalusers address, is that expected behavior?

Testing, I’ll edit this out in ~300 seconds and shortly after delete the link.

deleted.png

* * *

Edit#2

The link is deleted but the image persists in the edit history, perhaps it doesn’t have an `Upload` record as it isn’t removed by the automatic cleanup.

It’s hosted at [https://global.discourse-cdn.com/meta/original/3X/1/0/101f03af29f12ea30e1226eb96a02c3ed2f6d2ef.png](https://global.discourse-cdn.com/meta/original/3X/1/0/101f03af29f12ea30e1226eb96a02c3ed2f6d2ef.png). Not dropbox.

---

<div class="post-metadata">

### Author: ![anon47420739](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@anon47420739](https://meta.discourse.org/u/anon47420739)
#### Post date: [2 oktober 2020 om 19:12 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/24 "2020-10-02T19:12:56Z")

</div>

> [@anon47420739](#):
>
> Clicking “View Image” from the context menu takes me to a community.signalusers address, is that expected behavior?

I suppose, looking about, that it is held locally is expected behavior when `download_remote_images_to_local` is enabled. I think that’s the relevant setting.

So this

> [@anon47420739](#):
>
> So an image with an `upload` record that was never actually posted or was edited out of a comment would be deleted automatically. That correct?

isn’t functioning for this type of upload, as demonstrated in my previous post. Correct me if I’m wrong.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [2 oktober 2020 om 19:43 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/25 "2020-10-02T19:43:32Z")

</div>

The upload will be deleted if the site setting `clean up uploads` is enabled, after `clean orphan uploads grace period hours`.

---

<div class="post-metadata">

### Author: ![anon47420739](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@anon47420739](https://meta.discourse.org/u/anon47420739)
#### Post date: [2 oktober 2020 om 20:24 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/26 "2020-10-02T20:24:43Z")

</div>

Thanks for the quick response!

`clean up uploads` sounds like a general setting that would capture all images with an `upload` record, is that correct? Not just those present due to `download_remote_images_to_local`. If true, I should be able to find examples on the site of regular image uploads that aren’t being removed as a result of the automatic cleanup.

You mind me asking what the `clean orphan uploads grace period hours` is set to here so I can offer it as a solution. Or does it come with a default?

If they decide to enable that setting, will they need to do anything to apply it to past posts?

* * *

Edit  
Just for the sake of being explicit, the thinking here is that this isn’t an issue but that a setting needs to be switched on. I just don’t want to go back and say “You need to enable this!” and they say “It is enabled!” I’ll look silly.

---

<div class="post-metadata">

### Author: ![sebastianh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sebastianh/32/40415_2.png) [@sebastianh](https://meta.discourse.org/u/sebastianh)
#### Post date: [29 oktober 2020 om 22:19 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/27 "2020-10-29T22:19:38Z")

</div>

I also caught myself frantically looking for a place to browse uploads (familiar with it from MediaWiki) because I just know stuff gets double triple and quadruple uploaded, and sometimes I wonder where a file was that I uploaded once a while ago but maybe lost or deleted so I can link to it instead of re-uploading it yet again… I guess there is something to be said about a file browser… 🙂

---

<div class="post-metadata">

### Author: ![tanius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tanius/32/135041_2.png) [@tanius](https://meta.discourse.org/u/tanius)
#### Post date: [10 juli 2022 om 12:26 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/28 "2022-07-10T12:26:38Z")

</div>

I also had to somehow delete an uploaded file. We don’t have the cleanup task enabled as some files come from an import from a different forum software and have not yet been referenced in imported posts correctly. So I needed to find a manual way. The following works but is not pretty …

1. Make sure the relevant upload is no longer in the current version of any post. That way, Discourse will consider it orphaned and not make trouble when you delete it.

2. Use the [Data Explorer plugin](https://meta.discourse.org/t/32566) or a different way to query the Discourse database to list orphaned uploads, find the relevant one, and note down its upload\_id and filename. Relevant query:

3. In the database or with the [Rails console for Discourse](https://meta.discourse.org/t/15927/1), delete the concerned record from table `uploads` by its upload ID. Here I use the Rails console:

4. Delete the associated file incl. all optimized versions (if any, applies to images) from the file system via SSH. Note the wildcard added before the file extension to also catch optimized versions, which have a suffix here. Of course,

---

<div class="post-metadata">

### Author: ![anon98107012](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@anon98107012](https://meta.discourse.org/u/anon98107012)
#### Post date: [16 januari 2023 om 12:22 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/29 "2023-01-16T12:22:42Z")

</div>

> [@anon47420739](#):
>
> The link is deleted but the image persists in the edit history

Huh! Looks like the image referred to in this post is not captured by these settings:

> <https://github.com/discourse/discourse/blob/v3.0.0/config/site_settings.yml#L1372-L1374>

Why has it not been deleted?

May I also wonder why Discourse “uploads” a linked file such as the Dropbox link here? The point of linking a specific file will often be retaining control over content.

---

<div class="post-metadata">

### Author: ![LotusJeff](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lotusjeff/32/477888_2.png) [@LotusJeff](https://meta.discourse.org/u/LotusJeff)
#### Post date: [18 februari 2025 om 17:12 UTC](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001/30 "2025-02-18T17:12:25Z")

</div>

With the change of renaming post\_uploads to upload\_references, the SQL query listed in step 2 is no longer valid. The updated code is:

```sql
SELECT 
  uploads.id, uploads.user_id, uploads.created_at, 
  uploads.url, uploads.filesize
FROM uploads
  LEFT OUTER JOIN upload_references ON uploads.id = upload_references.upload_id
WHERE upload_references.target_id IS NULL
ORDER BY created_at DESC
LIMIT 100  

```

[Previous page](https://meta.discourse.org/t/how-to-delete-uploaded-files/25001.md?page=1)
