File

The file field can be used to accept files by browsing the file system, or simply by dragging and dropping a file onto the field. It can also be used to output a file for the user to download.

Example

({
  type: "file",
  accept: "image/*",
  label: "File",
})

Options

Input

Use these options when using the field with take.

accept?
string
The type of files the field will accept.
read?
"text" |‌ "data" |‌ "buffer"
The method used to read the data from the file, or render the data out to a file. The FileReader API is used, and these options map to readAsText, readAsDataURL and readAsArrayBuffer.
key?
string
A key to access the value. If provided, each field must have a unique key. See make for more information about accessing values.
label?
string
A label describing the purpose of the field.
detail?
string
Additional information about the field, disclosed in a tooltip.

Output

Use these options when using the field with make.

value?
string |‌ Blob
The content of the file for the user to download. If the value is a string, mimetype is required.
filename?
string
The name of the file to use if the user downloads the file.
mimetype?
string
The MIME type of the file. If the output value is a string, a MIME type is required. See common MIME types for more information.
label?
string
A label describing the purpose of the field.
detail?
string
Additional information about the field, disclosed in a tooltip.

Data

This input returns data in the specified format by read, or undefined if no selection has been made. If the user selects a file that does not match the accepted types, it is still read and passed to make.