File Reference and Deletion, will it really be deleted?

AI-generated summary

In a discussion titled “File Reference and Deletion, will it really be deleted?”, users explore how Discourse handles file deletion and storage management. xiasummer expresses concern about storage limits on a small 20GB server and asks whether removing file references from posts (e.g., deleting HTML link code) will actually delete the file and reduce backup size. Falco clarifies that if “clean up uploads” is enabled, unreferenced files are deleted after a grace period, and suggests reducing the max upload size from 100MB to 5–10MB. DeanMarkTaylor recommends using S3 for offloading uploads. fefrei asks whether files referenced in deleted posts are removed; vinothkannans confirms that if a post is fully deleted from the database and its attachments are unreferenced elsewhere, they will be removed. fefrei clarifies that UI deletion or editing (leaving link only in old revisions) doesn’t suffice — vinothkannans explains that if a post is soft-deleted or hidden, it’s not removed from the DB, so attachments remain; however, if only an old revision contains the link, the file will be removed. trobiyo asks whether attachments are deleted when posts/topics are deleted via UI in v2.0.2+; vinothkannans links to a related topic do-unlinked-files-get-auto-deleted/92215 for further details. sbernhard asks about deletion of files in private messages and suggests a “self-destructing” private message feature. The consensus is that files are only deleted if unreferenced and the post is fully removed from the database — not merely edited or soft-deleted.

I have a small server with only 20G of storage with my Discourse running on it. So I can’t let people upload too big files——of course if it is very important it should still be uploaded, but if not so important, it should not.

So I set the biggest upload file size 100M.

But I see many not so important files uploaded and the back-up quickly increases.

Here is a really small file I uploaded as an example:

try file.csv (6 字节)

with codes to be

<a class="attachment" href="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/f/8/f8c1d87006fbf7e5cc4b026c3138bc046883dc71.csv">try file.csv</a> 

What if I just delete such codes. Will the file “try file.csv” really be deleted from the server and will not cause any more burden on Discourse Backup File?

If clean up uploads is enabled, all uploads not referenced in posts will be removed after clean orphan uploads grace period hours.

If space is a problem, isn’t 100MB files a little too much? 5 or 10MB is enough most times.

6 likes

Consider setting up:

2 likes

Does this also affect attachments referenced in deleted posts?

Yes. If a post completely deleted and removed from database and it’s attachments not referenced anywhere else then it will be removed.

1 like

…so that means that “deletion” in the UI or editing the post so only an old revision contains the link is not enough to get a file removed, right?

From my understanding of the current code

If admin can see a post even after deletion (in soft delete or hidden mode) then it means post is not deleted in db. Then it will not removed.

In this case the media will be removed.

3 likes

Hi @vinothkannans

Could you please confirm that, in the latest versions (v.2.0.2 and so), when an administrator deletes topics/posts with attachments from UI, either individually or in bulk, those attachments are never removed from the server?

In case they aren’t, what’s the best approach to totally removed from server?

Cheers,
Ismael

Also there are many other related topics.

2 likes

Yes, exactly, that’s what I was looking for :ok_hand:

Thank you very much!

when are uploaded files to private messages are deleted?

Additionally, it would be great to have something like a “self-destroying” private message which will delete the sender and receiver message including the attached files after X hours /days.

1 like