FileInput
FileInput
component allows users to select and upload files.Basic usage
value
on the
component state.tsxCopied1<FileInput id="fileInput" label="Resume" placeholder="Upload" />2<Text>The file name is {fileInputState.value?.name}</Text>
Customizing the file selection
multiple
prop is set. You can also specify a comma-separated
list of MIME types to restrict the possible files that can be selected.value
on the component state is an array when multiple
is true.tsxCopied1const FileInputMultiple = () => {2const fileInputState = useComponentState("fileInput");34return (5<Stack>6<FileInput7id="fileInput"8label="Images"9placeholder="Upload"10accept={["image/jpeg", "image/png"]}11multiple12/>13<Text>The file names are {fileInputState.value?.map((f) => `"${f.name}"`).join(", ")}</Text>14</Stack>15);16};
Basic variant
variant
to
basic
.tsxCopied1<FileInput id="fileInput" variant="basic" label="Resume" placeholder="Upload" />2<Text>The file name is {fileInputState.value?.name}</Text>
Airplane integration
FileInput
automatically uploads selected files to Airplane, and packages each file with its upload
metadata in airplane.AirplaneFile
objects. AirplaneFile
implements the
Blob API and includes a name
field, so it
can largely be used as a regular JavaScript File
object. However, the additional upload metadata
allows it to be passed to tasks that are configured to accept file parameters, like so:Copied1const fileState = useComponentState("fileInputId");2const { mutate } = useTaskMutation({3slug: "task_slug",4params: { file_param: fileState.value?.[0] },5});
Component API
An array of MIME types to accept. For example, ["image/png", "image/jpeg"].
Whether the user can clear the input.
The input's disabled state on initial render.
Description displayed below the input.
Disables the input. Prefer to use defaultDisabled and component state.
If true, disables drag and drop. This prop is ignored if variant is "basic".
Error displayed below the input.
If set, this function will be used to get the upload url for selected files. For convenience, the id field of AirplaneFiles created by this component is set to the upload ID returned by the promise.
If true, the element will grow to fill available space.
This prop works only if the element is a direct child of a Stack.
The ID referenced by the global component state.
Label displayed above the input.
The maximum number of files that can be selected. This prop is ignored if variant is "basic".
The maximum allowable file size in bytes. This prop is ignored if variant is "basic".
Determines whether multiple files can be selected.
Callback function for when the file(s) in the file input changes.
Hint text displayed when the input is empty.
The input's border radius.
Adds red asterisk on the right side of label and sets required on input element
A single function or an array of functions that validate the input value.
Selected file(s) if using this component as a controlled component. Prefer to use the component state to get the value.
The file input variant, either dropzone or basic.
State API
Whether the file input is disabled
Sets the disabled value of the file input. If the disabled
value is not provided, the file input will be disabled
Sets the value of the file input
The file or files currently in the file input