The DocumentPicker
class provides an interface to the iOS document picker, allowing users to select files or directories and export files from within the Files app. This is useful for scripts that need to access user files, share content, or organize resources in a specified directory.
PickFilesOption
Options for configuring file selection with pickFiles
.
initialDirectory
(optional)
string
types
(optional)
string[]
shouldShowFileExtensions
(optional)
boolean
true
.allowsMultipleSelection
(optional)
boolean
false
.ExportFilesOptions
Options for exporting files using exportFiles
.
initialDirectory
(optional)
string
files
Array<{ data: Data; name: string }>
data
: The file data.name
: The file name.DocumentPicker.pickFiles(options?: PickFilesOption): Promise<string[]>
Allows users to pick files from the Files app.
options
(optional): PickFilesOption
string[]
).DocumentPicker.pickDirectory(initialDirectory?: string): Promise<string | null>
Allows users to pick a directory from the Files app.
initialDirectory
(optional): string
string
, or null
if the user canceled the picker.DocumentPicker.exportFiles(options: ExportFilesOptions): Promise<string[]>
Exports files to the Files app.
options
: ExportFilesOptions
string[]
).DocumentPicker.stopAcessingSecurityScopedResources(): void
Relinquishes access to security-scoped resources, like files or directories accessed via the document picker. Use this method when you no longer need access to these resources to ensure your app manages resources efficiently.