Skip to main content
On this pageFunctions

File

Functions

mimeType

functionsource
/** The file's MIME type (e.g. `"application/pdf"`), or empty string if the browser cannot determine one. */
(file: File): string

name

functionsource
/** The file's name including extension, as reported by the browser. */
(file: File): string

readAsArrayBuffer

functionsource
/**
 * Reads the file's contents as raw binary data. Mirrors Elm's `File.toBytes`.
 * 
 * Use this when you need the full binary payload (e.g. to upload, hash, or
 * parse a custom file format). For images you usually want `readAsDataUrl`
 * instead.
 */
(file: File): Effect<ArrayBuffer, FileReadError>

readAsDataUrl

functionsource
/**
 * Reads the file's contents as a base64-encoded data URL. Useful for rendering
 * image previews without uploading the file first. Mirrors Elm's `File.toUrl`.
 */
(file: File): Effect<string, FileReadError>

readAsText

functionsource
/**
 * Reads the file's contents as a UTF-8 string. Mirrors Elm's `File.toString`.
 * 
 * Fails with a `FileReadError` if the browser's `FileReader` encounters an
 * error (e.g. the file was deleted while reading). Handle failures with
 * `Effect.catchAll` to convert them into a failure Message.
 */
(file: File): Effect<string, FileReadError>

select

functionsource
/**
 * Opens the native file picker allowing a single file to be selected. Resolves
 * with an array containing the selected file, or an empty array if the user
 * cancelled. Mirrors Elm's `File.Select.file`.
 * 
 * The `accept` argument is a list of MIME types or file extensions that
 * restrict what the picker shows. Pass an empty array to allow any file.
 */
(accept: readonly Array<string>): Effect<readonly Array<File>>

selectMultiple

functionsource
/**
 * Opens the native file picker allowing multiple files to be selected at
 * once. Resolves with the array of selected files, or an empty array if the
 * user cancelled. Mirrors Elm's `File.Select.files`.
 */
(accept: readonly Array<string>): Effect<readonly Array<File>>

size

functionsource
/** The file's size in bytes. */
(file: File): number

Types

File

typesource
/**
 * A file selected by the user. Direct alias for the browser's native `File`
 * type — opaque by convention (Foldkit never constructs files itself, only
 * receives them from `File.select`, `File.selectMultiple`, or from
 * `OnFileChange`/`OnDropFiles` event attributes).
 */
type File = globalThis.File

Constants

File

constsource
/**
 * Schema that accepts any value that is an instance of the DOM `File` class.
 * Use in Model fields that hold user-selected files:
 * 
 * ```ts
 * attachedResume: S.OptionFromSelf(File.File)
 * ```
 */
const File: Schema<File, File, never>

Stay in the update loop.

New releases, patterns, and the occasional deep dive.


Built with Foldkit.

© 2026 Devin Jameson