GitHub
npm
expo-document-picker
provides access to the system's UI for selecting documents from the available providers on the user's device.
Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
-
npx expo install expo-document-picker
If you're installing this in a bare React Native app, you should also follow these additional installation instructions.
For iOS, outside of the Expo Go app, the DocumentPicker module requires the iCloud Services Entitlement to work properly. You need to take the following steps:
usesIcloudStorage
key to true
in your app.json as specified configuration properties.iCloud.<your_bundle_identifier>
.To apply these changes, you have to revoke your existing provisioning profile and use EAS Build to build the app binaries.
For iOS bare projects, the DocumentPicker
module requires the iCloud entitlement to work properly. If your app doesn't have it already, you can add it by opening the project in Xcode and following these steps:
Capabilities
tabon
iCloud Documents
checkboxWhen using expo-document-picker
with expo-file-system
, it's not always possible for the file system to read the file immediately after the expo-document-picker
picks it.
To allow the expo-file-system
to read the file immediately after it is picked, you'll need to ensure that the copyToCacheDirectory
option is set to true
.
import * as DocumentPicker from 'expo-document-picker';
DocumentPicker.getDocumentAsync(namedParameters)
Name | Type | Description |
---|---|---|
namedParameters (optional) | DocumentPickerOptions | - |
Display the system UI for choosing a document. By default, the chosen file is copied to the app's internal cache directory.
Notes for Web: The system UI can only be shown after user activation (e.g. a
Button
press). Therefore, callinggetDocumentAsync
incomponentDidMount
, for example, will not work as intended. Thecancel
event will not be returned in the browser due to platform restrictions and inconsistencies across browsers.
Returns
On success returns a promise that fulfils with DocumentResult
object.
If the user cancelled the document picking, the promise resolves to { type: 'cancel' }
.
DocumentPickerOptions
Name | Type | Description |
---|---|---|
copyToCacheDirectory (optional) | boolean | If Default: true |
multiple (optional) | boolean | Only for: Web Allows multiple files to be selected from the system UI. Default: false |
type (optional) | string | string[] | The MIME type(s) of the documents that are available
to be picked. It also supports wildcards like Default: '*/*' |