Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

File

Functions

download
(
file
:
File
)
:
Void

Prompts a dialog for the saving the given file.

file = await File.select(*)

File.download(file)
fromString
(
contents
:
String
name
:
String
type
:
String
)
:
File

Creates a new file from the contents, name and mime-type.

File.fromString("Some contents...", "test.txt", "text/plain")
mimeType
(
file
:
File
)
:
String

Returns the mime type of the file.

(File.fromString("Some contents...", "test.txt", "text/plain")
|> File.mimeType()) == "text/plain"
name
(
file
:
File
)
:
String

Returns the name of the file.

(File.fromString("Some contents...", "test.txt", "text/plain")
|> File.name()) == "test.txt"
readAsArrayBuffer
(
file
:
File
)
:
Promise(ArrayBuffer)

Reads the contents of the given file as a String.

file =
  File.create("Some content...", "test.txt", "text/plain")

File.readAsArrayBuffer(file)
readAsDataURL
(
file
:
File
)
:
Promise(String)

Reads the contents of the given file as a Data URL.

files =
  await File.select("text/plain")

url =
  File.readAsDataURL(file)

url == "data:text/plain;...."
readAsString
(
file
:
File
)
:
Promise(String)

Reads the contents of the given file as a String.

file =
  File.create("Some content...", "test.txt", "text/plain")

url =
  await File.readAsString(file)

url == "Some content..."
select
(
accept
:
String
)
:
Promise(File)

Opens the browsers file dialog for selecting a single file.

  • The mime type can be restricted to the given one.

  • It might not resolve if the user cancels the dialog.

    file = await File.select("application/json")

    Debug.log(file)

selectMultiple
(
accept
:
String
)
:
Promise(Array(File))

Opens the browsers file dialog for selecting multiple files.

  • The mime type can be restricted to the given one.

  • It might not resolve if the user cancels the dialog.

    files = await File.selectMultiple("application/json")

    Debug.log(files)

size
(
file
:
File
)
:
Number

Returns the size of the file in bytes.

(File.fromString("Some contents...", "test.txt", "text/plain")
|> File.size()) == 16