@TW_Tones What @Scott_Sauyet has doesn’t work for me, because that creates a download link, whereas I need to initiate the download immediately, as a button has already been pressed to generate the png in the first place.
What you put above doesn’t work because the tm-download-file is trying to render the image using the imageParser", as the image tiddler’s type warrants. This creates a link, (e.g. <img source="data:image/png;base64,AG34..." ></img>
). But then the download action only knows how to pull content from that either as text/plain or as text/html, and since it’s anything other than an html type (it’s an image type). It pulls the resulting parse-tree-node’s “textContent”, which is nothing, because it was an open-and-shut <img>
element.
Here’s something that does work, but only if we merge my PR.
\procedure download-binary-actions()
<$action-sendmessage $message="tm-download-file" $param="$:/core/templates/plain-text-tiddler" type={{{ [{!!type}addsuffix[;base64]]}}} currentTiddler=<<currentTiddler>> filename=<<currentTiddler>>/>
\end download-binary-actions
<$let currentTiddler="$:/favicon.ico">
<$button actions=<<download-binary-actions>> >
Download <<currentTiddler>> as {{!!type}}
</$button>
This renders the content first using $:/core/templates/plain-text-tiddler
's type, which is text/html. That template spits out its current tiddler as plain-text, so you get a wall of base64 text. Then same as before, the download action tries to pull content from that as either text/plain or as text/html based on the requested type, and since image/png
isn’t html, it gets plaintext. In this case, the blob of base64.
But my code also plugs the ;base64
onto the end of the type, so even though tiddlywiki is only offering raw base64, it says it’s a ;base64
type, and our browsers can figure it out and decrypt while downloading. So long as it’s presented as a download link and not a blob, which is what my PR does.
This is not great, but it works for me. What you wrote should be able to work exactly as is, but I didn’t push a PR to do that. Instead, it’s very minimal, because I get the sense we’re trying to stabilize TW right now as we’re moving toward V5.4.0. (I’m figuring this from the way none of my PRs in the last month have been merged.).