Auto attach images as resources after external editor

I have the same problem

Here is my unperfect solution. Using joplin web clipper.
Here is my python code. Please change "xxxxxxxxxxxxxxxx" to your joplin web clipper token before use.

import requests
import sys
import json

index = -1
for arg in sys.argv:
    index += 1
    if(index == 0):
        continue

    url = "http://127.0.0.1:41184/resources/?token=xxxxxxxxxxxxxxxx"
    payload = {'props': '{}'}
    files=[
      ('data',('typora.png',open(arg,'rb'),'image/png'))
    ]
    headers = {}
    response = requests.request("POST", url, headers=headers, data=payload, files=files)

    print("resources/"+json.loads(response.text)["id"]+".png")

And in typora, use custom command, enter:
your\full\path\to\Python\Python312\python.exe this\python\file\path\test.py

And you should "edit from outside editor" in joplin for edit typora in the same time. Also don't forget to click "upload image" button in typora. By doing that, what you import in your typora will upload to joplin resources.

But you will get an error, says typora can't replace the url.
It's because typora doesn't think "resources/id.png" is a legit url, but this is the last thing I can do: just copy the path and replace old link by myself...

So, if you upload all your images to other server(not joplin), then you can follow the typora docs. But if you want upload images to joplin resources in typora, my solution is almost perfect...

Now I'm thinking replace url using joplin plugin, I think it's a solution, but it may also be too unnecessary.

Hi
Thank you for sharing your solution.
But, sorry, Can you explain in a simple way how is the process for attaching any image using Typora as external editors?. Are you using web clipper + python script? Thanks.

Joplin web clipper has the access to your local joplin resources, so we can use python script to load image to joplin. Typora can use custom command to upload image, so we can upload to joplin using Python script. But typora can not replace the link with "resources/joplin_resources_id.png" which is the exact joplin path (because typora think it is a illegitimate url). So we can use python script to replace the content by write the markdown file.

Typora custom command works when the command output link lines as result. And typora will pass the typora local image path as command parameters. If you need upload your image to other server (not joplin), then my solution is not your choice.

1 Like

Thank you for providing this detailed explanation. It is clear to me, and I will make use of it."

I have updated my solution in Github: GitHub - a1473838623/Joplin-Typora-images-paste: Paste your images in Typora and upload images to Joplin using Python scripts.
If you are interested, you can check out.

2 Likes