Modules · Connectivity · Storage

Storage

Files, form fields and file pickers. Storage models a picked or captured file as a reactive Storage.File value — its name, MIME type, size in bytes and Base64-encoded contents — and gives you the inputs, form fields and picker payloads that fill one in. A file or image input binds to an optional Storage.File state, so the surrounding view updates the moment the user chooses or clears a file. Files serialise to and from Code.Language.Json.Value, so a chosen file can travel in a form submission or be stored and restored.

Contents

Types

Functions

Types

Storage.File

A picked or captured file: its name, MIME type, size and Base64-encoded contents. It also groups the file operations.

Fields

FieldTypeDescription
fileNameTextThe file's name, including its extension.
mimeTypeTextThe file's MIME type, such as image/png.
base64DataTextThe file's bytes, Base64-encoded.
fileSizeBytesMaths.IntegerThe file's size in bytes.

Definition

TYPE Storage.File
  FIELD Text fileName
  FIELD Text mimeType
  FIELD Text base64Data
  FIELD Maths.Integer fileSizeBytes
A file carries its name, type, contents and size together.

Example

STATE Collection.Optional(Storage.File) chosen = none
A reactive cell that holds the chosen file, or nothing yet.

Storage.PickerEmit

The payload a picker sends to the native layer, naming the picker and the state cells it should write back to.

Fields

FieldTypeDescription
pickerTypeTextWhich picker to open, such as camera or file.
fileSettableIdMaths.IntegerReference to the file state the picker writes the result into.
visibleSettableIdMaths.IntegerReference to the visibility state the picker closes when done.

Definition

TYPE Storage.PickerEmit
  FIELD Text pickerType
  FIELD Maths.Integer fileSettableId
  FIELD Maths.Integer visibleSettableId
An internal bridge payload built by Storage.PickerEmit.FromBindings.

Functions

Storage.File.Data

Builds a file value from its name, type, contents and size.

Parameters

NameTypeDescription
fileNameTextThe file's name.
mimeTypeTextThe file's MIME type.
base64DataTextThe file's Base64-encoded contents.
fileSizeBytesMaths.IntegerThe file's size in bytes.

Returns

Returns Storage.File — a file value carrying the given details.

Example

LET Storage.File file = Storage.File.Data name mime data size
Assembles a reactive file from its parts.

Storage.File.FromJson

Rebuilds a file from a JSON value.

Parameters

NameTypeDescription
jsonCode.Language.Json.ValueThe JSON object to read.

Returns

Returns Storage.File — the file described by json, with missing fields defaulting to empty.

Example

LET Storage.File file = Storage.File.FromJson saved
Restores a file from previously stored JSON.

Storage.File.FromJsonOptional

Rebuilds a file from an optional JSON value, staying absent when the input is.

Parameters

NameTypeDescription
optionalJsonCollection.Optional(Code.Language.Json.Value)The JSON to read, or nothing.

Returns

Returns Collection.Optional(Storage.File) — the rebuilt file, or nothing when optionalJson is absent.

Storage.File.GetBase64Data

The file's Base64-encoded contents.

Parameters

NameTypeDescription
fileStorage.FileThe file to read.

Returns

Returns Text — the file's bytes, Base64-encoded.

Storage.File.GetFileName

The file's name.

Parameters

NameTypeDescription
fileStorage.FileThe file to read.

Returns

Returns Text — the file's name, including its extension.

Storage.File.GetFileSizeBytes

The file's size in bytes.

Parameters

NameTypeDescription
fileStorage.FileThe file to read.

Returns

Returns Maths.Integer — the file's size in bytes.

Storage.File.GetMimeType

The file's MIME type.

Parameters

NameTypeDescription
fileStorage.FileThe file to read.

Returns

Returns Text — the file's MIME type, such as image/png.

Storage.File.ToJson

Serialises a file to a JSON value.

Parameters

NameTypeDescription
fileStorage.FileThe file to serialise.

Returns

Returns Code.Language.Json.Value — a JSON object holding the file's fields.

Storage.FormField.File

A form-integrated file field that registers its value, runs validation and shows errors.

Parameters

NameTypeDescription
nameTextThe field's name within the enclosing form.
labelTextThe label shown above the input.

Block

A validation block run with the field's current value as Collection.Optional(Text) — absent when no file is chosen; report a problem from inside it to mark the field invalid.

Returns

Returns nothing — it renders the labelled field, publishes its value to the form and shows any error or success.

Storage.FormField.Image

A form-integrated image field that registers its value, runs validation and shows errors.

Parameters

NameTypeDescription
nameTextThe field's name within the enclosing form.
labelTextThe label shown above the input.

Block

A validation block run with the field's current value as Collection.Optional(Text) — absent when no image is chosen; report a problem from inside it to mark the field invalid.

Returns

Returns nothing — it renders the labelled field, publishes its value to the form and shows any error or success.

Storage.Input.File

A file input showing the chosen filename and a Select button, bound to a file state.

Parameters

NameTypeDescription
fileCollection.Optional(Storage.File)A binding to the file state the input reads and writes; shows “No file chosen” while absent.

Returns

Returns nothing — it renders the input and updates file when the user picks or clears one.

Example

STATE Collection.Optional(Storage.File) chosen = none
Storage.Input.File chosen
Binds a file input to a reactive chosen cell.

Storage.Input.Image

An image input showing the chosen filename and a Select button, bound to a file state.

Parameters

NameTypeDescription
fileCollection.Optional(Storage.File)A binding to the file state the input reads and writes; shows “No image chosen” while absent.

Returns

Returns nothing — it renders the input and updates file when the user picks or clears an image.

Storage.PickerEmit.FromBindings

Packages picker bindings into an emit payload the native picker can write back through.

Parameters

NameTypeDescription
pickerTypeTextWhich picker to open, such as camera or file.
fileCollection.Optional(Storage.File)A binding to the file state the picker writes its result into.
visibleLogic.MaybeA binding to the visibility state the picker closes when done.

Returns

Returns Storage.PickerEmit — the payload carrying the picker's type and the referenced state cells.