Skip to main content

Handling Files and Binary Data

In Windmill, JSON is the primary data format used for representing information. When working with binary data, such as files, they are represented as Base64 encoded strings. Those Base64 strings can not be distinguished from normal strings. Hence, the interpretation those Base64 encoded strings it either done depending on the context, or by pre-fixing those strings with the <data specifier:>.

In explicit contexts, when the JSON schema specifies that a property represents Base64-encoded data:

foo:
type: string
format: base64

If necessary, Windmill automatically converts it to the corresponding binary type in the corresping language as defined in the schema. In python, it will be converted to the bytes type. In Typescript, they are simply represented as strings.

In ambiguous situations (file ino) where the context does not provide clear indications, it is necessary to precede the binary data with the data:base64 encoding declaration.

In the app editor, in some cases when there is no ambiguity, the data prefix is optional.

Base64 encoded strings are used in:

  • File Input component in the app editor: files uploaded are converted and returned as a Base64 encoded string.
  • Download Button: the source to be downloaded must be in Base64 format.
  • File inputs to run scripts must be typed into the JSON string, encodingFormat: base64 (python: bytes, Deno: wmill.Base64).