Document picker
DocumentPicker opens the system's file picker, bound to expo-document-picker: the Files app's
browser on iOS and the storage access framework on Android.
import { DocumentPicker } from '@ng-native/expo';
inject(DocumentPicker)The options are the module's own, passed through unchanged. A canceled picker answers with no files rather than a result to unwrap, and the system picker needs no permission, so none is asked for.
Install
npx expo install expo-document-pickerimport { DocumentPicker } from '@ng-native/expo/document-picker';The smallest useful example
import { Component, inject, signal } from '@angular/core';
import { DocumentPicker } from '@ng-native/expo/document-picker';
@Component({
selector: 'app-attach',
template: `
<pressable (press)="attach()"><text>Attach a PDF</text></pressable>
<text>{{ attached() }}</text>
`,
})
export class Attach {
private readonly documents = inject(DocumentPicker);
protected readonly attached = signal('');
protected async attach(): Promise<void> {
const [file] = await this.documents.pick({ type: 'application/pdf' });
if (file) this.attached.set(file.name);
}
}What it does
pick(options?)- opens the picker and resolves to the files chosen, empty if the user canceled. Each is the module's ownDocumentPickerAsset:uri,name,mimeType,sizeandlastModified.type- a MIME type such as'image/*', or a list of them. Everything by default.multiple- allow more than one file.copyToCacheDirectory- on by default: each file is copied into the app's cache, so the file system and other Expo modules can read itsuri. Off leaves the platform's own reference, which only some readers understand.base64- on the web, whether eachuriis the file's contents as base64. On by default.
Without the module
On iOS and Android, a missing expo-document-picker - never installed, or installed without the app
being rebuilt since - throws a MissingModuleError when the service first reaches for it. Its
message names the module and the commands that fix it; see
Using a module.
On the web, and in a test that provides no fake, pick() resolves to an empty list.
Reference
DocumentPickerservice@ng-native/expoimport { DocumentPicker } from '@ng-native/expo';Methods
pick(options?: DocumentPickerOptions): Promise<readonly PickedDocument[]> Opens the system picker. type is a MIME type or a list of them, multiple allows more than one file, and copyToCacheDirectory (the default) copies each into the app's cache so other Expo modules can read it. Empty if they cancelled.