Future-proofing links to embedded files (e.g. personal photos on NAS storage)

What I’m trying to do

I am trying to find a way I can future-proof links to my personal media files stored (currently) on my NAS storage so that i can reference them/embed them into my notes. This way, if in the future I find myself having to move the media file directory to another service or location I can just update the root path in one place and still have my obsidian vault finding my files.

Things I have tried

I have tried creating a “global variable” (in this example, stored in a file in my vault “+GlobalVars+”):

=[[+GlobalVars+]].media_root

I’m able to successfully access and append this to create the file path to a file, for example:
=[[+GlobalVars+]].media_root/2016-03/2016-03-01/100.JPG

However, what I’m trying to do in order to embed the file doesn’t work but also is very clunky to do long-term. Does anyone have a better way of achieving this? Below is what I’ve been trying with:
[[=[[+GlobalVars+]].media_root + "/2016-03/2016-03-01/100.JPG"]]

1 Like

Hi all,

As way of an update, I’ve found “something” that gets me a step closer - in that I can access medial files outside of my Obsidian Vault:

[Test link to local files](<file:////Volumes/MyExternalHD/MyFolder/2023/2023-01/2023-01-01/MyPhoto.jpg>)

However, I can not see a way to generalise it with my [[+GlobalVars+]].media_root:

---
media_root: /Volumes/MyExternalHD/MyFolder
---

Can anyone help me get to the bottom of this problem? Your help would be very much appreciated! I remember seeing something once that some javascript could be run at the start of Obisidian startup and I’m wondering if is could be somehow to generate the whole section in parentheses in a function?

I think your best bet is to user a dv.view() function to generate the link, and then that script could have the media root hard coded.

You could then do stuff like:

`= dv.view("js/medialink", ["link description", "media/file.png"]) `

Do however be aware that embedding is a little clunky in any solution.

If you’re only using reading view, and not live preview, you could also consider using Templater user functions, for a slightly leaner function call, like:

<%+ tp.user.medialink("link description", "media/file.png") %>