caption: encodebase64
created: 20240831034955575
from-version: 5.2.6
modified: 20240831035003716
op-input: a [[selection of titles|Title Selection]]
op-output: the input with base 64 encoding applied
op-parameter: 
op-parameter-name: 
op-purpose: apply [[base 64|Base64]] encoding to a string
op-suffix: optional: `binary` to treat input as binary data, `urlsafe` for URL-safe output
tags: [[Filter Operators]] [[String Operators]]
title: encodebase64 Operator
type: text/vnd.tiddlywiki

See Mozilla Developer Network for details of [[base 64 encoding|https://developer.mozilla.org/en-US/docs/Glossary/Base64]]. TiddlyWiki uses [[library code from @nijikokun|https://gist.github.com/Nijikokun/5192472]] to handle the conversion.

The input strings are interpreted as [[UTF-8 encoded|https://developer.mozilla.org/en-US/docs/Glossary/UTF-8]] text (or binary data instead if the `binary` suffix is present). The output strings are base64 encoded.

The optional `binary` suffix, if present, causes the input string to be interpreted as binary data instead of text. Normally, an extra UTF-8 encoding step will be added before the base64 output is produced, so that emojis and other Unicode characters will be encoded correctly. If the input is binary data, such as an image, audio file, video, etc., then the UTF-8 encoding step would produce incorrect results, so using the `binary` suffix causes the UTF-8 encoding step to be skipped.

The optional `urlsafe` suffix, if present, will use the alternate "URL-safe" base64 encoding, where `-` and `_` are used instead of `+` and `/` respectively, allowing the result to be used in URL query parameters or filenames.

<<.operator-examples "encodebase64">>
