# Backend - Image model - uri pointing to file in cache\_dir?

**URL:** https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139
**Category:** Misc
**Created:** [September 10, 2021, 2:57am UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139 "2021-09-10T02:57:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![natumbri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/natumbri/32/1164_2.png) [@natumbri](https://discourse.mopidy.com/u/natumbri)
#### Post date: [September 10, 2021, 2:57am UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/1 "2021-09-10T02:57:50Z")

</div>

If a backend extension saves an image in the `cache_dir`, can it then point to that file in a mopidy Image model, like this:

```auto
{uri: [Image(uri=f"file://{os.path.join(cache_dir, filename)}")]}

```

---

<div class="post-metadata">

### Author: ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)
#### Post date: [September 10, 2021, 7:28am UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/2 "2021-09-10T07:28:10Z")

</div>

No, They need to be accessible over the network for clients to use.

---

<div class="post-metadata">

### Author: ![natumbri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/natumbri/32/1164_2.png) [@natumbri](https://discourse.mopidy.com/u/natumbri)
#### Post date: [September 10, 2021, 11:27am UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/3 "2021-09-10T11:27:16Z")

</div>

Thanks @kingosticks

Cheers,  
Nik

---

<div class="post-metadata">

### Author: ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)
#### Post date: [September 10, 2021, 11:43am UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/4 "2021-09-10T11:43:16Z")

</div>

Also, as a related note (but it doesn’t matter for what you are trying to do), you can’t rely on anything in cache\_dir to be there. It might be cleared on reboot or other times. cache\_dir is for caching. We have data\_dir for stuff you want to persist.

---

<div class="post-metadata">

### Author: ![natumbri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/natumbri/32/1164_2.png) [@natumbri](https://discourse.mopidy.com/u/natumbri)
#### Post date: [September 10, 2021, 1:06pm UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/5 "2021-09-10T13:06:24Z")

</div>

Yeah, it is for cache - if the file is there, return an Image object that points to the file; if it’s not there point to the url and save the image in the cache the first time it is accessed. But it sounds like there’s no way to do that.

Someone requested caching: caching the audio and the metadata is pretty straightforward, but caching the image, it seems, isn’t.

Cheers  
Nik

---

<div class="post-metadata">

### Author: ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)
#### Post date: [September 10, 2021, 2:51pm UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/6 "2021-09-10T14:51:43Z")

</div>

Well, Mopidy does have a built-in HTTP server. So you could leverage that, just like [GitHub - mopidy/mopidy-local-images: DEPRECATED (Mopidy local library proxy extension for handling embedded album art)](https://github.com/mopidy/mopidy-local-images)

But if the user has disabled (or misconfigured) their HTTP extension then it won’t work.

---

<div class="post-metadata">

### Author: ![natumbri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/natumbri/32/1164_2.png) [@natumbri](https://discourse.mopidy.com/u/natumbri)
#### Post date: [September 10, 2021, 10:26pm UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/7 "2021-09-10T22:26:05Z")

</div>

Yes, I actually had exactly the same thought, overnight!

Ta

---

<div class="post-metadata">

### Author: ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/system/32/1_2.png) [@system](https://discourse.mopidy.com/u/system)
#### Post date: [March 12, 2022, 10:27am UTC](https://discourse.mopidy.com/t/backend-image-model-uri-pointing-to-file-in-cache-dir/5139/8 "2022-03-12T10:27:00Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
