# Are images deleted if they are no longer included in any note?

**URL:** <https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608>\
**Category:** Support\
**Created:** [8 December 2019 16:25 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608 "2019-12-08T16:25:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![n00b12345](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/n00b12345/32/1112_2.png) [@n00b12345](https://discourse.joplinapp.org/u/n00b12345)\
**Post date:** [8 December 2019 16:25 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/1 "2019-12-08T16:25:18Z")

</div>

In general, are images deleted if I delete their links from a note?

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [9 December 2019 11:31 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/2 "2019-12-09T11:31:55Z")

</div>

If a resource is no longer referenced, it should be deleted after 24h. But there’s a bug so this does not always happen.

---

<div class="post-metadata">

**Author:** ![plong8080](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@plong8080](https://discourse.joplinapp.org/u/plong8080)\
**Post date:** [9 December 2019 14:45 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/3 "2019-12-09T14:45:45Z")

</div>

This has been a problem for quite a while. Do you know if there are any plans to fix this in the near future, winter, spring?

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [9 December 2019 15:36 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/4 "2019-12-09T15:36:15Z")

</div>

Nope, I don’t know. But at one point Laurent mentioned something in that regard, but I can’t remember what it was.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [9 December 2019 15:47 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/5 "2019-12-09T15:47:37Z")

</div>

I don’t have a solution at the moment, except maybe enforcing a one-to-one relationship between notes and resources, but even that would be tricky to implement.

---

<div class="post-metadata">

**Author:** ![plong8080](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@plong8080](https://discourse.joplinapp.org/u/plong8080)\
**Post date:** [9 December 2019 17:26 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/6 "2019-12-09T17:26:37Z")

</div>

Thanks. I wish I could help code a solution with you, but I’m sure the code would be over my head. I am in the process of creating a python script to clean out the resources folder of orphaned files which is going well so far. If I delete the orphaned files from the resources folder, will I also have to remove the records that reference them in the note\_resources where is\_associated = 0?

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [10 December 2019 06:40 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/7 "2019-12-10T06:40:24Z")

</div>

You shouldn’t manipluate the database manually. There are a bunch of scripts already available (check the #apps category), but removing all resources where `is_associated = 0` could lead to data loss, if you’re using note history.

---

<div class="post-metadata">

**Author:** ![plong8080](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@plong8080](https://discourse.joplinapp.org/u/plong8080)\
**Post date:** [10 December 2019 10:44 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/8 "2019-12-10T10:44:11Z")

</div>

Ok Thanks. I guess I’ll wait for you guys to fix it properly.

---

<div class="post-metadata">

**Author:** ![joeschmoe](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/joeschmoe/32/9127_2.png) [@joeschmoe](https://discourse.joplinapp.org/u/joeschmoe)\
**Post date:** [26 May 2020 17:47 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/9 "2020-05-26T17:47:19Z")

</div>

any update on this ?

---

<div class="post-metadata">

**Author:** ![joeschmoe](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/joeschmoe/32/9127_2.png) [@joeschmoe](https://discourse.joplinapp.org/u/joeschmoe)\
**Post date:** [30 May 2020 19:46 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/10 "2020-05-30T19:46:44Z")

</div>

If this still isn’t working, I’ll write something to clear unlinked resources. Can someone please let me know so I don’t waste my time ? @tessus ?

---

<div class="post-metadata">

**Author:** ![CalebJohn](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/calebjohn/32/356_2.png) [@CalebJohn](https://discourse.joplinapp.org/u/CalebJohn)\
**Post date:** [30 May 2020 21:07 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/11 "2020-05-30T21:07:02Z")

</div>

If you check the apps category you can probably find some resources to help with that. For example tessus has [some scripts](https://discourse.joplinapp.org/t/scripts-to-remove-orphaned-resources/2853) for cleaning unlinked resources. Those will probably be enough for you.

---

<div class="post-metadata">

**Author:** ![joeschmoe](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/joeschmoe/32/9127_2.png) [@joeschmoe](https://discourse.joplinapp.org/u/joeschmoe)\
**Post date:** [4 June 2020 20:22 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/12 "2020-06-04T20:22:02Z")

</div>

I wrote my own and I noticed it ended up deleting more stuff that @tessus’s script didn’t catch.

`sudo gem install joplin` and then run `joplin clean --token a6f0459...` to run it. also has a `-n` for a dry-run. Mine’s much slower because it uses the Joplin API fully

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [4 June 2020 23:38 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/13 "2020-06-04T23:38:26Z")

</div>

> [@joeschmoe](#):
>
> it ended up deleting more stuff

This might not be good. Are you sure you took the note history into account? If you run my script with the options `--zero-history` or `--ignore-revisions` you might see the same number of "orphans" as in your script. However, please do ONLY run this with the `--dry-run` option. Otherwise you will most likely lose data.

---

<div class="post-metadata">

**Author:** ![joeschmoe](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/joeschmoe/32/9127_2.png) [@joeschmoe](https://discourse.joplinapp.org/u/joeschmoe)\
**Post date:** [7 June 2020 20:31 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/14 "2020-06-07T20:31:15Z")

</div>

> [@tessus](#):
>
> This might not be good. Are you sure you took the note history into account?

Using the notes endpoint I got resources for all notes, then using the resources endpoint I got all the resources that exist. Then I delete all the resources that didn't exist in any notes.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [7 June 2020 20:38 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/15 "2020-06-07T20:38:44Z")

</div>

I’m pretty sure there’s a bug in resource cleanup logic. Or more likely in sync logic. I mentioned elsewhere on the forum that I’ve inspected my database and found some lines in `note_resources` table that are obviously broken.

I’m not yet sure as to what the root cause (though I have an idea), will try to investigate further.

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [7 June 2020 20:57 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/16 "2020-06-07T20:57:14Z")

</div>

The problem is that I do not know, if the API actually takes the history into account either. This is something only @laurent would know - or someone who worked at the note history code.

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [7 June 2020 20:59 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/17 "2020-06-07T20:59:49Z")

</div>

> [@roman\_r\_m](#):
>
> I’m pretty sure there’s a bug in resource cleanup logic

Laurent mentioned several times that there's a reason why the current implementation does not catch all resources. But I can't recall the exact explanation. I think it had something to do with the `n:m` relationship of notes and resources.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [7 June 2020 23:28 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/18 "2020-06-07T23:28:07Z")

</div>

There’s some info about this bug in this issue: [https://github.com/laurent22/joplin/issues/932](https://github.com/laurent22/joplin/issues/932)

---

<div class="post-metadata">

**Author:** ![stj](https://avatars.discourse-cdn.com/v4/letter/s/7993a0/32.png) [@stj](https://discourse.joplinapp.org/u/stj)\
**Post date:** [15 February 2021 15:18 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/19 "2021-02-15T15:18:08Z")

</div>

Hi... A quick query.

Files/images that are no longer attached to a note are automatically deleted after 24 or 48 hours? In some places, I see 24, and in another, 48 hours.

Usecase:

- Note A has two images added to it along with some text
- It's all synced up to the cloud(Dropbox). The setup is E2EE.
- I delete Note A.

So, in this case, when those two images that I added to Note A be automatically deleted?

---

<div class="post-metadata">

**Author:** ![Wimvan](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/wimvan/32/12536_2.png) [@Wimvan](https://discourse.joplinapp.org/u/Wimvan)\
**Post date:** [18 February 2022 19:37 UTC](https://discourse.joplinapp.org/t/are-images-deleted-if-they-are-no-longer-included-in-any-note/4608/20 "2022-02-18T19:37:54Z")

</div>

You may have a look here:

> [@When do images/resources clear out](https://discourse.joplinapp.org/t/when-do-images-resources-clear-out/23600/2):
>
> Joplin needs the images as long as it saves the note history. You can edit this under Tools -\> Options -\> Note History. After that period of time is over, Joplin will delete the files not needed anymore. I also remember that Laurent was vague when asked for a detailed schedule / trigger for the deletion, when asked here in the forum. HTH
