> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/expo/expo/llms.txt
> Use this file to discover all available pages before exploring further.

# expo-document-picker

> Access system UI for selecting documents from available providers on the device

# expo-document-picker

**Version:** 55.0.6

Provides access to the system's UI for selecting documents from the available providers on the user's device. On iOS, this uses `UIDocumentPickerViewController`, on Android it uses `Intent.ACTION_GET_CONTENT`, and on web it uses the HTML file input element.

## Installation

```bash theme={null}
npx expo install expo-document-picker
```

## Usage

```typescript theme={null}
import * as DocumentPicker from 'expo-document-picker';
import { Button, View, Text } from 'react-native';

export default function App() {
  const [document, setDocument] = React.useState<string | null>(null);

  const pickDocument = async () => {
    const result = await DocumentPicker.getDocumentAsync({
      type: '*/*',
      copyToCacheDirectory: true,
    });

    if (!result.canceled) {
      setDocument(result.assets[0].uri);
      console.log('Selected:', result.assets[0].name);
    }
  };

  return (
    <View>
      <Button title="Pick Document" onPress={pickDocument} />
      {document && <Text>Selected: {document}</Text>}
    </View>
  );
}
```

## API Reference

### Methods

<ParamField path="getDocumentAsync(options)" type="(options?: DocumentPickerOptions) => Promise<DocumentPickerResult>">
  Displays the system UI for choosing a document

  **Parameters:**

  * `type` (string | string\[]): MIME types to filter documents. Defaults to `'*/*'`
  * `copyToCacheDirectory` (boolean): Copy selected file to cache directory. Defaults to `true`
  * `multiple` (boolean): Allow selecting multiple files. Defaults to `false`
  * `base64` (boolean): Include base64 representation. Defaults to `false`

  **Returns:** Promise resolving to `DocumentPickerResult`

  ```typescript theme={null}
  // Pick a single PDF
  const result = await DocumentPicker.getDocumentAsync({
    type: 'application/pdf',
  });

  // Pick multiple images
  const result = await DocumentPicker.getDocumentAsync({
    type: ['image/png', 'image/jpeg'],
    multiple: true,
  });

  // Pick any file with base64
  const result = await DocumentPicker.getDocumentAsync({
    type: '*/*',
    base64: true,
  });
  ```
</ParamField>

### Types

#### DocumentPickerResult

```typescript theme={null}
type DocumentPickerResult =
  | {
      canceled: false;
      assets: DocumentPickerAsset[];
    }
  | {
      canceled: true;
      assets: null;
    };
```

#### DocumentPickerAsset

<ResponseField name="uri" type="string">
  The URI of the selected document
</ResponseField>

<ResponseField name="name" type="string">
  The name of the selected file
</ResponseField>

<ResponseField name="size" type="number">
  Size of the file in bytes
</ResponseField>

<ResponseField name="mimeType" type="string">
  MIME type of the file
</ResponseField>

<ResponseField name="base64" type="string | undefined">
  Base64 representation if requested
</ResponseField>

#### DocumentPickerOptions

<ParamField path="type" type="string | string[]">
  MIME type(s) to filter. Examples: `'image/*'`, `'application/pdf'`, `['image/png', 'image/jpeg']`
</ParamField>

<ParamField path="copyToCacheDirectory" type="boolean">
  Whether to copy the selected file to the app's cache directory. Defaults to `true`
</ParamField>

<ParamField path="multiple" type="boolean">
  Allow selecting multiple documents. Defaults to `false`
</ParamField>

<ParamField path="base64" type="boolean">
  Include base64 representation in the result. Defaults to `false`
</ParamField>

## Examples

### Pick a PDF File

```typescript theme={null}
import * as DocumentPicker from 'expo-document-picker';

async function selectPDF() {
  const result = await DocumentPicker.getDocumentAsync({
    type: 'application/pdf',
    copyToCacheDirectory: true,
  });

  if (!result.canceled) {
    const file = result.assets[0];
    console.log('PDF selected:', file.name);
    console.log('URI:', file.uri);
    console.log('Size:', file.size, 'bytes');
  }
}
```

### Pick Multiple Images

```typescript theme={null}
import * as DocumentPicker from 'expo-document-picker';

async function selectImages() {
  const result = await DocumentPicker.getDocumentAsync({
    type: 'image/*',
    multiple: true,
  });

  if (!result.canceled) {
    console.log(`Selected ${result.assets.length} images`);
    result.assets.forEach((file) => {
      console.log('Image:', file.name, file.uri);
    });
  }
}
```

### Pick Document with Base64

```typescript theme={null}
import * as DocumentPicker from 'expo-document-picker';

async function selectWithBase64() {
  const result = await DocumentPicker.getDocumentAsync({
    type: '*/*',
    base64: true,
  });

  if (!result.canceled && result.assets[0].base64) {
    const base64Data = result.assets[0].base64;
    // Upload or process base64 data
    await uploadToServer(base64Data);
  }
}
```

### Filter by Multiple MIME Types

```typescript theme={null}
import * as DocumentPicker from 'expo-document-picker';

async function selectDocuments() {
  const result = await DocumentPicker.getDocumentAsync({
    type: [
      'application/pdf',
      'application/msword',
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    ],
  });

  if (!result.canceled) {
    console.log('Document:', result.assets[0].name);
  }
}
```

### Complete Example with State

```tsx theme={null}
import * as DocumentPicker from 'expo-document-picker';
import { useState } from 'react';
import { View, Button, Text, FlatList, StyleSheet } from 'react-native';

export default function DocumentPickerExample() {
  const [documents, setDocuments] = useState<DocumentPickerAsset[]>([]);

  const pickDocuments = async () => {
    try {
      const result = await DocumentPicker.getDocumentAsync({
        type: '*/*',
        multiple: true,
        copyToCacheDirectory: true,
      });

      if (!result.canceled) {
        setDocuments(result.assets);
      }
    } catch (error) {
      console.error('Error picking documents:', error);
    }
  };

  return (
    <View style={styles.container}>
      <Button title="Pick Documents" onPress={pickDocuments} />
      
      <FlatList
        data={documents}
        keyExtractor={(item) => item.uri}
        renderItem={({ item }) => (
          <View style={styles.item}>
            <Text style={styles.name}>{item.name}</Text>
            <Text style={styles.size}>
              {(item.size / 1024).toFixed(2)} KB
            </Text>
          </View>
        )}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, padding: 20 },
  item: { padding: 10, borderBottomWidth: 1, borderColor: '#ccc' },
  name: { fontSize: 16, fontWeight: 'bold' },
  size: { fontSize: 14, color: '#666', marginTop: 4 },
});
```

## Platform Support

| Platform | Supported |
| -------- | --------- |
| iOS      | ✅         |
| Android  | ✅         |
| Web      | ✅         |

## Common MIME Types

| Type       | MIME String                       |
| ---------- | --------------------------------- |
| All files  | `'*/*'`                           |
| PDF        | `'application/pdf'`               |
| Images     | `'image/*'`                       |
| Videos     | `'video/*'`                       |
| Audio      | `'audio/*'`                       |
| Text       | `'text/plain'`                    |
| Word       | `'application/msword'`            |
| Excel      | `'application/vnd.ms-excel'`      |
| PowerPoint | `'application/vnd.ms-powerpoint'` |

<Note>
  On web, the system UI can only be shown after user activation (e.g., a button press). The `canceled` event may not be returned consistently across browsers due to platform restrictions.
</Note>

## Resources

* [Official Documentation](https://docs.expo.dev/versions/latest/sdk/document-picker/)
* [GitHub Repository](https://github.com/expo/expo/tree/main/packages/expo-document-picker)
