File
Functions
Prompts a save dialog for the given file.
sequence {
file =
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 Data URL.
sequence {
file =
File.fromString("Some content...", "test.txt", "text/plain")
url =
File.readAsDataURL(file)
url == "data:text/plain;...."
}
Reads the contents of the given file as a String.
sequence {
file =
File.create("Some content...", "test.txt", "text/plain")
url =
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.
sequence { file = 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.
sequence { files = 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