Button
High level file upload component for multiple file selection.
This component provides a button to trigger multiple file selection. To display selected files, manage state yourself and use PreviewFile or FileUploadList.
Parameters
Callback invoked when files are selected
Text label for the default button
Modifier to be applied to the button
The size of the button. Only applies when using the default buttonContent.
The optional icon to be displayed at the start or the end of the button container. Only applies when using the default buttonContent.
If an icon is added, you can configure the side where is should be displayed, at the start or end of the button. Only applies when using the default buttonContent.
Type of files to select (image, video, file, etc.)
Maximum number of files that can be selected. If null, no limit.
Optional title for the file picker dialog
Optional directory to open the picker in
Optional settings for the file picker dialog
Whether the button is enabled
If provided, it'll be spoken in place of the default "double tap to activate".
Composable lambda for custom button. Receives onClick callback. Defaults to a filled button with the label.
Samples
var selectedFile by rememberSaveable { mutableStateOf<UploadedFile?>(null) }
Column(modifier = Modifier.fillMaxWidth()) {
FileUpload.ButtonSingleSelect(
onResult = { file -> selectedFile = file },
label = "Select a file",
modifier = Modifier.fillMaxWidth(),
)
VerticalSpacer(16.dp)
selectedFile?.let { file ->
PreviewFile(
file = file,
onClear = { selectedFile = null },
modifier = Modifier.fillMaxWidth(),
onClick = { FileUploadDefaults.openFile(file) },
)
}
}var selectedFiles by remember {
mutableStateOf<ImmutableSet<UploadedFile>>(persistentSetOf())
}
Column(modifier = Modifier.fillMaxWidth()) {
FileUpload.Button(
onResult = { files ->
selectedFiles = selectedFiles.plus(files).toImmutableSet()
},
label = "Add files",
modifier = Modifier.fillMaxWidth(),
)
VerticalSpacer(16.dp)
if (selectedFiles.isNotEmpty()) {
FileUploadList(
files = selectedFiles.toImmutableList(),
onClearFile = { file ->
selectedFiles = selectedFiles.filterNot { it == file }.toImmutableSet()
},
onClick = { file -> FileUploadDefaults.openFile(file) },
)
}
}