Importing - option between link and copy

When importing an external document (i.e. a PDF file) into a wiki, is there an option (via a dialog) just to create a link to the document or to import the whole document
(something similar to the Windows Explorer dialog ‘Copy here’, ‘Move here’, or ‘Create link here’)?

-Reinhard

Addendum:

The $browse widget would be a great place for such a functionality. Or does it already exist, and I just missed somenthing?

It’s actually a little bit more complicated that it might seem at first glance. Here’s a little bit of background info:

Internally, the <$browse> widget creates an HTML <input type="file"> element. This element is handled by the browser’s native code to display a system-provided “folder/file” dialog. After navigating to the desired folder and selecting a file, you press the “open” button. This returns two primary pieces of information for the selected file (or files, if the multiple="multiple" parameter was specified).

  1. The “filename.ext” of each selected file
  2. The base64-encoded file content of each selected file.

TiddlyWIki’s <$browse> widget then invokes a tm-import-tiddlers message that triggers the generation and display of the TWCore system $:/Import tiddler interface, which allows you to complete the process of creating tiddlers using the “filename.ext” and base64-encoded file content information returned by the system.

Note that the system does NOT give you the full path to each selected file… just the “filename.ext” portion. This is done by the overly paranoid browser-native code as a security measure in order to avoid exposing information about your directory structure, which might be used by some kind of exploit that is “probing” your system for nefarious purposes.

Thus, while the <$browse> widget let’s you select local files and create tiddlers with the base64-encoded file contents, you can’t use it to automatically create external file tiddlers that have a _canonical_uri field with a full path and filename reference.

Note that it is possible to create external file references when using TiddlyWiki invoked via the Nodejs command line. (see https://tiddlywiki.com/#ExternalImages).

However, because of the security limitation described above, this process relies upon a special TWCore template – https://tiddlywiki.com/#%24%3A%2Fcore%2Ftemplates%2Fcanonical-uri-external-image – that manually specifies the desired “base URI” to prepend to the filename.ext provided by the system folder/filename dialog.

In order to change this “base URI” from the default ./images/ prefix, you need to edit the template, as noted in a comment within that template:

Change the `./images/` part to a different base URI. The URI can be relative or absolute.

-e

1 Like

@EricShulman

Thanks for the explanation!
I will use the Nodejs command.

-Reinhard

@EricShulman unfortunately, or fortunately this is not the end of the story.

For example If I provide the full path and filename in the _canonical_uri field, and tiddler type, I can reference images in other locations see below;

By the way thanks for you very good explanation above.

file://studiodisk/Home/Gouldian%20Finch%201%20tsp.JPG

The point here is from the browser you can’t use the dialogue box to select a full folder and path however if you can get the “full folder and path” from elsewhere such as explorer/finder etc… (And I expect it is not in some prohibited locations) then it can be used.

This works in my Windows 11, Chrome Browser from a single file wiki where the external image and the wiki are served from different LAN Shares.

Posts script;
If files and folders on your current desktop can be accessed via a share then you may be able to set the _canonical_uri to that address.

As Eric has noted, browsers don’t provide the full pathname to the file. Typically they provide access to the filename.

But TiddlyDesktop extends the browse widget so that the full pathname is provided. That allows the External Attachments plugin to offer the option of creating _canonical_uri links for imported tiddlers, instead of embedding them.

1 Like

On filenames please see this reply/thread. Could the browserstorage help avoid users loosing data - #50 by TW_Tones