How to get the source path when Drag-and-Drop or copying a file image from outside

I am currently working on a plugin to synchronize data between Obsidian and a software that manages attachments.
I’ve run into a problem, so I’m looking for help.
I want to get the source path of an image when copying it externally or dragging and dropping it, but this seems to be difficult to accomplish.
I noticed that there is a way to do this through Electron, but my testing doesn’t seem to be working with this method. It could be that there is no correct import { clipboard } from “electron”;.
Also I noticed that obsidian’s native functionality has the ability to press ctrl, when dragging and dropping an image, to get the path. I wonder if this could be of some help.

Translated with DeepL.com (free version)

const file = clipboardEvent.clipboardData.files[0];
// or
const file = dropEvent.dataTransfer.files[0];

const path = electron.webUtils.getPathForFile(file);
3 Likes

Thanks a lot, was able to get the file path correctly. :pray: :grinning: :grinning:

1 Like