SwiftUI.js
Components

FileImporter

FileImporter presents a button-backed file picker and forwards selected files to your app.

FileImporter presents a button-backed file picker and forwards selected files to your app.

Examples

Default

Preview unavailable for this example in the static docs build.

Show code
function DemoFileImporter() {
  const [value, setValue] = useState('No file selected')

  return (
    <VStack spacing={12}>
      <FileImporter onSelect={(files) => setValue(files.map((file) => file.name).join(', '))}>
        Import file
      </FileImporter>
      <Text>{value}</Text>
    </VStack>
  )
}

Multiple Selection

Preview unavailable for this example in the static docs build.

Show code
<VStack spacing={12}>
      <FileImporter
        allowedContentTypes={['image/png', 'image/jpeg']}
        allowsMultipleSelection
        onSelect={() => undefined}
      >
        Import images
      </FileImporter>
      <Text>Uses SwiftUI-style selection aliases for accepted content types and multiple selection.</Text>
    </VStack>

API

PropTypeRequiredDescription
acceptstringNoAccepted file types.
allowedContentTypesstring[]NoSwiftUI-aligned alias for accepted file types.
multiplebooleanNoWhether multiple files can be selected. Default: false
allowsMultipleSelectionbooleanNoSwiftUI-aligned alias for multiple selection. Default: false
onSelect(files: Array<globalThis.File>) => voidYesCalled with the selected files.

Inherits additional props from Omit<IBaseElementComponent<'button'>, 'type' | 'onSelect'>.

Overview

FileImporter presents a button-backed file picker and forwards selected files to your app.

Notes

  • allowedContentTypes and allowsMultipleSelection are the preferred SwiftUI-aligned props.
  • The hidden input is reset after each selection so the same file can be chosen again in a subsequent import flow.

On this page