What are the differences between these adapter methods: getBasePath, getFullPath, getRealPath, getFullRealPath?

There are several suggested methods for app.vault.adapter: getBasePath, getFullPath, getRealPath, getFullRealPath. What are the differences between them?

app.vault.adapter.getResourcePath("foo")
"app://local/D%3A%5CQu%E1%BA%A3%20C%E1%BA%A7u%5CB%20N%E1%BB%99i%20dung%5CKnowledge%20graphs%5CC%C3%A2y%20v%E1%BA%A5n%20%C4%91%E1%BB%81%5Cfoo?1645084573664"

app.vault.adapter.getBasePath("foo")
"D:\Quả Cầu\B Nội dung\Knowledge graphs\Cây vấn đề"

app.vault.adapter.getFullPath("foo")
"D:\Quả Cầu\B Nội dung\Knowledge graphs\Cây vấn đề\foo"

app.vault.adapter.getRealPath("foo") 
"foo"

app.vault.adapter.getFullRealPath("foo")
"D:\Quả Cầu\B Nội dung\Knowledge graphs\Cây vấn đề\foo"

The official doc doesn’t explain much.

In the Discord @pjeby says:

getResourcePath() converts a vault-relative path to a URL that can be used to access the file from the HTML, e.g. to load as a <script> tag, <iframe>, <img>, etc. You only need it if you specifically need the browser to load it in some way

I put the outcome in my browser, but it just read it as a query for google (meaning that it doesn’t understand that it’s a link).

When I said “the browser”, I meant Obsidian’s UI browser, which is a Chrome browser on the desktop and Android, and I believe Safari/Webkit on iOS.

Obsidian’s UI is implemented in HTML, and if you need it to render files as images or scripts or what-have-you in the Obsidian UI, then you can use the URLs returned by getResourcePath() to do that. They are useless outside of Obsidian itself.

2 Likes

I see. Do you know the answer for the question about the differences between the methods?

getBasePath() returns the base path of the vault - it doesn’t take arguments. The full variants get the base path plus the path given, the real variants translate symlinks I believe. If you’re not using symlinks I think the real versions will return the same things.

But I don’t 100% know… mostly because roughly 95% of all plugins should never be using any of these methods, ever.

Never use an adapter method when a vault method will do. The only time you need to use the adapter is to access special files like hidden files or files inside the .obsidian (or vault.configDir) directory, or if you are desktop-exclusive and need to run other programs that require a real filesystem path, or you need to use a node API on desktop that needs a file and can’t just be given the contents.

(Even then, you should not use node APIs to access files if there’s any way to do it with the vault APIs instead, as that will make your plugin desktopOnly.)

1 Like

The only time you need to use the adapter is to access special files like hidden files or files inside the .obsidian (or vault.configDir) directory, or if you are desktop-exclusive and need to run other programs that require a real filesystem path, or you need to use a node API on desktop that needs a file and can’t just be given the contents.

Why do we need to have a separate property for these? Security?