@react-native-gpui/documents-picker
v11.0.0
Published
Adapter for @react-native-documents/picker (MIT): opens the operating system file and folder pickers
Readme
@react-native-gpui/documents-picker
Adapter for @react-native-documents/picker (MIT): opens the operating system file and folder pickers.
About
This package is the desktop adapter for @react-native-documents/picker 11.0. Install the original library next to it; the library's JavaScript runs unchanged. The upstream library is licensed under the MIT license.
Install
npm install @react-native-documents/picker @react-native-gpui/documents-pickerThe module is autolinked on desktop.
Usage
import {
pick,
pickDirectory,
saveDocuments,
keepLocalCopy,
types,
isErrorWithCode,
errorCodes,
} from '@react-native-documents/picker';
try {
const [file] = await pick({ type: [types.images, types.pdf] });
const [copy] = await keepLocalCopy({
files: [{ uri: file.uri, fileName: file.name ?? 'file' }],
destination: 'cachesDirectory',
});
} catch (e) {
if (isErrorWithCode(e) && e.code === errorCodes.OPERATION_CANCELED) return;
throw e;
}Behaviour on desktop
pickopens the system open panel.allowMultiSelectionselects several files. Cancelling rejects withOPERATION_CANCELED, as on mobile. Each result has afile://uri,name,sizeand atypeguessed from the extension.typeis turned into extension filters. Predefinedtypes.*, UTIs (public.image), MIME types (image/*,application/pdf) and.extstrings are understood;*/*andpublic.itemallow any file, and unknown values are ignored.pickDirectoryopens the folder panel and resolves with the folder'sfile://uri.saveDocumentswith one source opens the save panel (prefilled withfileName, or the source name) and writes the file there. With several sources it asks for a folder. As on iOS the files are moved unlesscopy: true.keepLocalCopycopies into<cache or data dir>/<app id>/<uuid>/<fileName>and resolves with afile://localUri.documentDirectoryis the user data directory.isKnownTyperesolves from a built-in table for the predefined types and from MIME and extension data otherwise.releaseSecureAccessandreleaseLongTermAccesssucceed without doing anything.requestLongTermAccessreturns no bookmark, as desktop paths stay valid.presentationStyle,transitionStyleandallowVirtualFilesare ignored. Panels are not attached to the app window.
Platforms
macOS is tested. Windows and Linux are not tested yet.
Limitations
Options that only exist on mobile (iCloud, persistable URI permissions) are ignored; see Behaviour on desktop.
License
MIT. See LICENSE. The upstream library, @react-native-documents/picker, is MIT licensed.
