When you attach files to a note are they copied there?

[Hi, first post so I hope I picked the right topic.]

When I attach a file to a note - an image (those appear to show in line), a video, a PDF or other, etc - what exactly happens with it. Does it:

A) actually copy that file into the note, so it exists there independently,

  • If this: when move that note around (say syncing it to a remote backup, or even just manually sending the note to myself somewhere else) will it also move all the files that are attached to that note around as well?

B) It’s not actually copying the file to a note, but rather just points to the file on your device where it is actually stored.

  • If this: what kind of effect would things like moving the original file to a different folder, changing the name or some other piece of metadata about it, or even deleting it have on its ability to show in the note?

Thanks

[For full context, I am talking about the mobile app mostly, but if there is a different behaviour for the desktop client an answer for that would also be great. FYI in this case I am syncing to the local device file system, not a cloud service]

What problem do you want to solve exactly? If you want to know the implementation details, the best is to check the source code. Otherwise in general it’s supposed to work in a way you’d expect, and if it doesn’t then that’s what we need to know.

Well to be honest I’m not trying to fix a problem per se. I am a non-expert user and I am literally just trying to understand what happens when I attach a file.

Basically knowing whether I need to keep the original or not, how modifying it might affect the note and that kind of thing.

It’s often easier to answer questions when there’s a specific issue, as your questions are more about implementation details.

In general, the app is supposed to be intuitive so let’s say if you copy a note to a different notebook, the file attachments will be copied there too. If you export as PDF or HTML file, the attachments will be exported too, etc. That’s what, as a user, I’d expect.

If something is not working as you’d expect, then feel free to ask here.

1 Like

In general, the app is supposed to be intuitive so let’s say if you copy a note to a different notebook, the file attachments will be copied there too.

Okay, so just to be clear, very basic ELI5 level.

  1. if I have a file I want to add to a note, say 2 MB JPG or PDF, and I am using the mobile, and I choose the “attach” option, it will take that file and make another new copy of an Envy Joplin repository / database. So if I ever delete the original from my phone, that will not affect the attachment in the note?

  2. Say this note is in “Notebook A”, and I copy it into " Notebook B", you are saying that it will also make another duplicate copy of this file in the local Joplin database? Or it will just generate a new link pointing to the same first copy in the Joplin database?

I also want to know if we can safely delete the original file or is Joplin simply pointing to the file path where the original file is stored?

If the answer is no, that means I have to keep a separate folder for all my files and Joplin is mostly going to be used for all plaintext notes with a bunch of file paths.

By the sounds of your reply, it sounds like the answer is yes and we will have nothing to worry about. Joplin will save all attachments by the act of 'attaching' a file (rather than 'attaching' a file path). So if I am exporting a JEX (Joplin Export File) then is it like a zip file which contains all my attachments?

You can delete the originals.

Pretty much, yes.

Thanks @roman_r_m, how do I edit an attachment that is already attached to Joplin?

Let’s say I attach a spreadsheet to a note, where do I find that spreadsheet? I guess it’s OS dependant, I’m using Kubuntu so would it be somewhere in the home directory?

I think in one of the latest versions you can open the attachment for edit from Joplin. I’ve never used this feature though.

On Windows, on viewer mode, when you right click a file path, it will show you an option Reveal file in folder, im on joplin 1.0.220 and it does not work though, I will test this on newer version when I have the time. The other option below it is Copy path to clipboard which i currently use, I just paste this on my 3rd party filemanager and it shows me the path.

Yes but Joplin will rename the file to a random generated id so I think its better for some files to have it stored outside. You can press ALT key to link files instead of copy.

Maybe we can have an option to have either link or copy as the default and press a key to change it

Option in Joplin
On drag+drop files/folder:
Create link to files/folder - ![] (file:///C:/Users/dgo/AppData/Local/Temp/msohtmlclip1/01/clip_image001.jpg)

Copy files/folder - 4603da4d82e037a2ff3d21f86fc84796.picture

Reference
Link to local file ressources?
How can I convert a file link to a resource link?

This was discussed before but I don’t remember what happened to it. Now that there’s progress towards a plugin system I imagine it can be added that way.

To be absolutely clear: if you mess with files outside of Joplin, don’t ask for support. Period.

If you want to edit an attachment, open it in Joplin (which will start the associated app) and edit it.

1 Like

Thanks for all the answers, I have another question. If I delete an attachment for a note, how does Joplin handle unlinked attachments? Theoretically, I could attach a thousand attachments to one note then delete them all. Is there a way to ‘clear’ the residual data that is no longer used?

@p2635

Joplin should delete unused resources after a set time. I cannot recall what that time period is, however I am sure @laurent mentioned it recently when replying to a post on this very topic.

I am not sure that it is working as efficiently as it could and if you actually search this forum for postings on orphaned or unattached resources you will get quite a few hits.

One such post from a few days ago that summarises the situation is:

1 Like

Is this what you do? Do you manage your files outside? That sounds good because we can keep the original file name instead of a generated ID.

There is a downside to doing that though. Let’s say you reinstall your OS then all the file paths may be relative and no longer valid. You will need to spend time correcting all the links to the new paths. I wonder if anyone has thought about this.

If you link, rather than attaching, you do not just keep the original file name, it is the original file. However your linked files will not be synced. Furthermore, in order for notes on different clients to be able to resolve the links you would have to manually duplicate the file structure / file locations / files on each device. This hits a problem not only because it is quite a task but also because it’s not possible between different OSs (Windows / Linux / Android / iOS). A link with a file path such as C:\users\name\Documents\folder\filename.pdf is only going to be of use to a Windows based OS (and only then if the username is the same on every Windows device).

If you do not use sync there can still be problems as if you move or rename the linked file the link breaks. There is also the situation you describe.

I would say that this has been thought about. It is why when you attach a file to a note it is copied to the Joplin resources folder and given a unique reference so Joplin can keep track of it. That way the file can be synced between all clients and can be resolved by all clients. I suppose that is why Joplin does not have a toolbar button or menu option to “link” to a local file, only one to “attach” a file.

Having a generated ID for resources is not a problem. The files in the resources folder are not there for the user; they are there for Joplin. Modifying the contents of that folder is likely to cause problems.

As a wise man once said,

To be absolutely clear: if you mess with files outside of Joplin, don’t ask for support. Period.
If you want to edit an attachment, open it in Joplin (which will start the associated app) and edit it.

2 Likes

I have some embedded files mostly pictures, and other files I manage outside using organized folders. You can also use apps with uri support like Zotero but you need to use scripts to open these for now
Open local files using autohotkey

That is one problem but you can solve it using the same folder structure. Another solution is using uri example zotero://someidhere, only problem with Zotero is it does not support adding folders so you have to add each file of a folder. I would like to see an app like Zotero with uri that support folders in WIndows

1 Like