Button to import image files listed in JSON array

Hi everyone

I have created a Tiddlywiki which allows me to view thumbnails of external images. Each image is a tiddler with a _canonical_uri field. The images are in a folder named images which is in the same parent folder as the wiki.

I can select individual thumbnail images using a checkbox and create a json array JsonImportList of those images that I want to import into my wiki.

[
{
“path”: “images/20241013-171025.jpg”
},
{
“path”: “images/20241105-141124.jpg”
}

]

The following code was supposed to automate the import process

<$button>
Import images
<$action-sendmessage $message=“tm-import-tiddlers” $param={{JsonImportList}}/>
</$button>

Unsurprisingly, it does not import the images; instead tiddlers with the full path as their title are created.

I assume that the JSON array must have just the image file names and not the full paths, but how do incorporate the path to the files into the above code?

Can anyone help.

Cheers, Rob

You can already view external images in TW and you wish to import selected image files into TW file ? I’m afraid “tm-import-tiddlers” doesn’t do that, nor any TW commands. It can’t be SCRIPTED using TW alone, because of browser security. Don’t want random external site you browse to to be able to import your local images using script without you knowing.

Note that importing images directly into TW is generally discouraged because images are huge compared to TW file and can cause TW file bloat. External image links are recommended instead.

However :

  • You can do it MANUALLY. By dragging and dropping an image into TW, even an external image displayed in your TW, like what you already have. You can also multi-select image files from you OS file manager* and drag them into TW.

* I’m not sure if and how TW can support multi-select and dragging of images displayed within itself.

  • TiddlyClip is a browser and TW plugin that allows you to clip images and text directly from web page into TW. I suppose there is nothing stopping TiddlyClip from clipping external images displayed within TW before pasting into TW itself :slight_smile:

Hi there,

I have been able to create external image tiddlers using the method described here:

The images to be imported are first listed in a data dictionary. Note that the code contains a small error - the action-createtiddler element is not closed, it should be:


<$action-createtiddler $basetitle=<<image>> _canonical_uri=<<gluepath>> type="image/jpeg"/>

Hope this helps

M

Thanks for your comments @jacng and @moonfish .

The link looks interesting.

I think my original request was unclear. I actually want to import the selected images in my JSON array as internal images.

The images to be imported are downsized so storage is not a problem.

For context, the wiki is a travel blog which I allow friends and family to download. Internal images removed the need for them to also download a separate folder of images.

Cheers, Rob

Hi Rob,

This could be what you are looking for:

https://talk.tiddlywiki.org/t/bulk-import-local-images-into-single-tiddler-as-links/

I think posts 8/9 have what you are looking for.

There’s a lot of useful info contained in the rest of the thread too.

M

Hello all

I have just realised that I am trying to use tm-import-tiddlers to import .jpg files!!

No wonder my script does not work. I think I am trying to do the impossible and will have to stick to manually dragging-and-dropping.

Cheers, Rob

Rob as mentioned elsewhere, the import button uses the $browse widget (not well named) see $:/core/ui/Buttons/import then review https://tiddlywiki.com/#BrowseWidget this is the way to customise the FILE import process as well. use the multiple attribute And by default the deserializer is derived from the file extension or type eg .jpg files.

Here is an example I use for non-image files

\whitespace trim
<span class="tc-file-input-wrapper browse-button">
<$browse multiple accept={{!!extensions}} tooltip={{{ [[Search for and Import one or more files with the extensions]] [{!!extensions}] +[join[  ]] }}}/>
{{!!caption}}
</span>

The extensions field contains .json, .tid, .txt, .csv to which you could add/replace *.jpg

  • See the accept parameter

Many thanks @TW_Tones Might be easier than dragging and dropping from folder to wiki.

Cheers, Rob