File
Functions
Prompts a dialog for the saving the given file.
file = await File.select(*)
File.download(file)
Creates a new file from the contents, name and mime-type.
File.fromString("Some contents...", "test.txt", "text/plain")
Returns the mime type of the file.
(File.fromString("Some contents...", "test.txt", "text/plain")
|> File.mimeType()) == "text/plain"
Returns the name of the file.
(File.fromString("Some contents...", "test.txt", "text/plain")
|> File.name()) == "test.txt"
Reads the contents of the given file as a String.
file =
File.create("Some content...", "test.txt", "text/plain")
File.readAsArrayBuffer(file)
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;...."
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..."
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)
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)
Returns the size of the file in bytes.
(File.fromString("Some contents...", "test.txt", "text/plain")
|> File.size()) == 16