Can I list a file's embeds/ attachments in a field using Metadata Menu?

What I’m trying to do

I am using Dataview and DBFolder to help manage my references in a table. Each row of the table contains a unique research article or other evidence source.

If I have a PDF or other attachment for a file, I’ll paste the attachment directly into the file so it is embedded and organized elsewhere. My default folder path for the attachments is an Attachments folder.

My problem is that I can’t easily tell which references have attachments embedded when looking through the table. Ideally, there would be a field that lists all embedded files for each row of the table.

Things I have tried

I first tried using the DB Folder formula field. But I have not been able to get that to work with any code (discussion on GitHub).

I’ve since been trying Metadata Menu’s formula field since it can update dynamically. This code works within a file so I’ve been trying variations of it in the formula field with no luck so far.

```dataviewjs
const {path} =  dv.app.workspace.getActiveFile();
// or you could also use const  path = "anyFilename.md";
const attachements = this.app.metadataCache.getCache(path).embeds;
let res = "List of attachements : </p>";
for (let att of attachements) {
res += att.link+"<br>";
}
const elt=dv.el("p",res);
```

Any ideas would be greatly appreciated!

How are you using Dataview for other parts? The reason I’m asking is that the embeds are readily available with some filtering on the file.outlinks array.

In any case, if other should test it would be nice to see a little more of your setup and/or queries.

1 Like

I should have clarified - I’m not using Dataview inside the table or inside of specific properties. It’s there as a necessary add-on with DB Folder for Notion-like databases.

I tried these in a Metadata Menu formula field based on this thread

dv.pages().filter(p => p.file.outlinks.values.map(l => l.path).includes("Attachments"))
dv.pages().filter(p => p.current.file.outlinks.values.map(l => l.path).includes("Attachments"))

This works inside of the page:

```dataviewjs
let outlinks = dv.array(dv.current().file.path).flatMap(p => dv.page(p).file.outlinks);

let attachments = Array.from(outlinks.filter(pageLinks => pageLinks.path.includes("Attachments")));

dv.list(attachments);
```

But it does not embed the link inside of the listed items:
image

And the code does not work in the Metadata Menu formula field.