Create notes including attachments for manual import

I have a plain text comic database including the path to files (png, jpg) of the cover pages.
Now I want to import this data into Joplin.
For that I wanted to use the import option “MD - Markdown Directory”.
I can create the markdown file and import it into Joplin.
Unfortunately I can’t work out how to link the cover pages located in the _resources folder to the markdown files in the parent directory.
In the forum I read some information about an UUID but can’t figure out how to apply it to the cover pages and the md files.
Unfortunately I’m not familiar with Java or Javascript but have some basic knowledge in Perl.
I’m running Joplin as Windows Desktop app.
Could you be so kind an give me a hint what the procedure could be to link the attachments to the md files to use the import option of the desktop app.

Thank you
Li

2 Likes

I don’t completely understand what you’re trying to do. Are you trying to attach an image to a note? If so, you can simply use the build-in feature - click on the paperclip button, select your image, and it will be attached to your note.

I have some pictures (cover pages of comic books) on my hard drive.
In a text database I have some meta data of the comics.
To have the data base available in Joplin I wanted to export my text database into the Joplin markup file.
The markup file shall display a table with information like comicbook title, number, etc.
Additionally I wanted to display the cover page of the comicbooks in the table.
Since there are several hundreds of comic books I can’t do that manually but looked for a way to generate the markdown files with a Perl script.
As mentioned above, the markdown files work as expected but I can’t figure out how to structure the cover pages and link them programmatically to the markdown.

with joplin terminal you can do:

joplin --profile ~/.config/joplin-desktop mknote test_attachment

add an attachment by

joplin --profile ~/.config/joplin-desktop attach <note> <file>

to spot the note id we do

joplin --profile ~/.config/joplin-desktop ls -l -t n -n 1 -f json

explanation :

ls -l 

like the command line :wink:

-t n

means you just want to list "note" (vs task with -t t )

-n 1 

means you want the 1irst one only

-f json 

-f is the output format, here json
the main pro of -f json is to be able to grab the stdout easily and avoid to use some |cut -d ''

here is my final output

joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json

[{"id":"7c46776072704f679a73d3e5eeeb4e14","title":"test_attachment","body":"","is_todo":0,"todo_completed":0,"parent_id":"e424345758da42e0be3d7a7574101a4e","updated_time":1536861769606,"user_updated_time":1536861769606,"user_created_time":1536861499476,"encryption_applied":0,"type_":1}]

then I can use attach

joplin --profile ~/.config/joplin-desktop attach 7c467 ~/Images/P_20180902_184400.jpg

you could notice that I did not provide the complet note ID because joplin ls -l display the first 4 car so you could use also 4 car or more

now

joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json
[{"id":"7c46776072704f679a73d3e5eeeb4e14","title":"test_attachment","body":"![P_20180902_184400.jpg](:/662ad00e97c540c890e8c8fdc00b644d)\n\n","is_todo":0,"todo_completed":0,"parent_id":"e424345758da42e0be3d7a7574101a4e","updated_time":1536861769606,"user_updated_time":1536861769606,"user_created_time":1536861499476,"encryption_applied":0,"type_":1}]

The image will be added at the end of the note.

Now, If you plan to deal with the image position, I wont export anything from the database into markdown file. Instead I will read the text database and wrap the joplin terminal to build the notes the way I want.

For example

In your perl script:

  1. you could split the text body in 3 pieces for example, to put the image after each piece of body
  2. run joplin mknote title1
  3. grab the note ID with
joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json
  1. joplin set <noteid_found_in_point_3> body body_piece1
  2. joplin attach <noteid_found_in_point_3> /path/to/image1.jpg
  3. repeat 4 and 5 for body_piece2 and body_piece3 and each attachment

ps : i'm not sure of the result with

joplin set <noteid_found_in_point_3> body body_piece1 

It's possible that with

joplin set <noteid_found_in_point_3> body body_piece2

the 2nd piece override the complet body.
In that case, to concatenate the content of the existing body, redo

joplin --profile ~/.config/joplin-desktop ls -t n -n 1 -s created_time -f json

to grab the "body" and then you could update the body withtout risk

1 Like

That's something for me to chew on :cold_sweat: - thank you.
Maybe a stupid question: How do I activate joplin terminal on Windows? Is it part of the Desktop application or do I have to install additional software as described in https://joplin.cozic.net/terminal/?

yes you need to install https://joplin.cozic.net/terminal/ it's not part of the joplin desktop.
once it's done, you will need to provide the profile to point on the joplin-desktop profile to use the same data (for terminal and desktop) from terminal and desktop. otherwise when you will start joplin terminal you will think you loose everything because in fact you will point to another profile :slight_smile:

don't worry we are here :slight_smile:

Hmm. I managed to do a raw import into the desktop application (markdown & pictures in a table) just by the help of a text editor and manually created uuid’s (to test what a script should do).
I thought - hey that’s easy - but the information doesn’t sync.
So it’s more complicated than I hoped it would be (maybe timestamps and other wrongly set meta data).

1 Like

make a try as you think it could be. in the markdown file try with the makrdown image tag with file:///path/to/image/folder/foobar.jpg

You need to use joplin web clipper api to scan markdown, then parse the local resources and upload them to joplin and replace them, and finally upload markdown itself as a note