Capacitor plugin that allows the user to select a file, directory, image, or video from the device's file system or gallery.
We are proud to offer one of the most complete and feature-rich Capacitor plugins for file picking. Here are some of the key features:
- 🖥️ Cross-platform: Supports Android, iOS and Web.
- 📂 Directory picking: Allows users to select a directory to retrieve all files.
- 🖼️ Image picking: Lets users select one or more images from the gallery.
- 🎥 Video picking: Lets users select one or more videos from the gallery.
- 📄 File picking: Lets users select one or more miscellaneous files from the file system.
- 📸 HEIC to JPEG conversion: Converts HEIC images to JPEG format on iOS.
- 📜 File metadata: Retrieves metadata such as file size, name, mime type, and last modified timestamp.
- 📦 CocoaPods & SPM: Supports CocoaPods and Swift Package Manager for iOS.
- 🔁 Up-to-date: Always supports the latest Capacitor version.
Missing a feature? Just open an issue and we'll take a look!
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.
| Plugin Version | Capacitor Version | Status |
|---|---|---|
| 8.x.x | >=8.x.x | Active support |
| 6.x.x | 6.x.x | Deprecated |
| 5.x.x | 5.x.x | Deprecated |
npm install @capawesome/capacitor-file-picker
npx cap syncThis API requires the following permissions be added to your AndroidManifest.xml before or after the application tag:
<!-- Needed if you want to retrieve unredacted EXIF metadata from photos -->
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<!-- Needed if you want to read files from external storage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>To use this plugin with Mac Catalyst, your app must have the com.apple.security.files.user-selected.read-only entitlement enabled. This allows the app to read files selected by the user. Check out the Apple documentation for more information.
<key>com.apple.security.files.user-selected.read-only</key>
<true/>If you don't want to use the plugin with Mac Catalyst, you can skip this step.
No configuration required for this plugin.
import { FilePicker } from '@capawesome/capacitor-file-picker';
const appendFileToFormData = async () => {
const result = await FilePicker.pickFiles();
const file = result.files[0];
const formData = new FormData();
if (file.blob) {
const rawFile = new File(file.blob, file.name, {
type: file.mimeType,
});
formData.append('file', rawFile, file.name);
}
};
const checkPermissions = async () => {
const result = await FilePicker.checkPermissions();
};
const copyFile = async () => {
const result = await FilePicker.copyFile({
from: 'path/to/file',
to: 'path/to/destination',
});
};
const pickFiles = async () => {
const result = await FilePicker.pickFiles({
types: ['image/png'],
});
};
const pickDirectory = async () => {
const result = await FilePicker.pickDirectory();
};
const pickImages = async () => {
const result = await FilePicker.pickImages();
};
const pickMedia = async () => {
const result = await FilePicker.pickMedia();
};
const pickVideos = async () => {
const result = await FilePicker.pickVideos();
};
const requestPermissions = async () => {
const result = await FilePicker.requestPermissions();
};checkPermissions()convertHeicToJpeg(...)copyFile(...)pickFiles(...)pickDirectory()pickImages(...)pickMedia(...)pickVideos(...)requestPermissions(...)addListener('pickerDismissed', ...)removeAllListeners()- Interfaces
- Type Aliases
checkPermissions() => Promise<PermissionStatus>Check permissions to access files.
Only available on Android.
Returns: Promise<PermissionStatus>
Since: 6.1.0
convertHeicToJpeg(options: ConvertHeicToJpegOptions) => Promise<ConvertHeicToJpegResult>Convert a HEIC image to JPEG.
Only available on iOS.
| Param | Type |
|---|---|
options |
ConvertHeicToJpegOptions |
Returns: Promise<ConvertHeicToJpegResult>
Since: 0.6.0
copyFile(options: CopyFileOptions) => Promise<void>Copy a file to a new location.
| Param | Type |
|---|---|
options |
CopyFileOptions |
Since: 7.1.0
pickFiles(options?: PickFilesOptions | undefined) => Promise<PickFilesResult>Open the file picker that allows the user to select one or more files.
| Param | Type |
|---|---|
options |
PickFilesOptions |
Returns: Promise<PickFilesResult>
pickDirectory() => Promise<PickDirectoryResult>Open a picker dialog that allows the user to select a directory.
Only available on Android and iOS.
Returns: Promise<PickDirectoryResult>
Since: 6.2.0
pickImages(options?: PickMediaOptions | undefined) => Promise<PickImagesResult>Pick one or more images from the gallery.
On iOS 13 and older it only allows to pick one image.
Only available on Android and iOS.
| Param | Type |
|---|---|
options |
PickMediaOptions |
Returns: Promise<PickFilesResult>
Since: 0.5.3
pickMedia(options?: PickMediaOptions | undefined) => Promise<PickMediaResult>Pick one or more images or videos from the gallery.
On iOS 13 and older it only allows to pick one image or video.
Only available on Android and iOS.
| Param | Type |
|---|---|
options |
PickMediaOptions |
Returns: Promise<PickFilesResult>
Since: 0.5.3
pickVideos(options?: PickMediaOptions | undefined) => Promise<PickVideosResult>Pick one or more videos from the gallery.
On iOS 13 and older it only allows to pick one video.
Only available on Android and iOS.
| Param | Type |
|---|---|
options |
PickMediaOptions |
Returns: Promise<PickFilesResult>
Since: 0.5.3
requestPermissions(options?: RequestPermissionsOptions | undefined) => Promise<PermissionStatus>Request permissions to access files.
Only available on Android.
| Param | Type |
|---|---|
options |
RequestPermissionsOptions |
Returns: Promise<PermissionStatus>
Since: 6.1.0
addListener(eventName: 'pickerDismissed', listenerFunc: () => void) => Promise<PluginListenerHandle>Called when the file picker is dismissed.
Only available on iOS.
| Param | Type |
|---|---|
eventName |
'pickerDismissed' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
Since: 0.6.2
removeAllListeners() => Promise<void>Remove all listeners for this plugin.
Since: 0.6.2
| Prop | Type | Description | Since |
|---|---|---|---|
accessMediaLocation |
PermissionState |
Permission state for accessing media location. On Android, this requests/checks the ACCESS_MEDIA_LOCATION permission. |
6.1.0 |
readExternalStorage |
PermissionState |
Permission state for reading external storage. On Android, this requests/checks the READ_EXTERNAL_STORAGE permission. |
6.1.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
path |
string |
The path of the converted JPEG image. | 0.6.0 |
| Prop | Type | Description | Since |
|---|---|---|---|
path |
string |
The path of the HEIC image. | 0.6.0 |
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
from |
string |
The path of the file to copy. | 7.1.0 | |
overwrite |
boolean |
Whether to overwrite if the file at destination already exists. | true |
7.2.0 |
to |
string |
The path to copy the file to. | 7.1.0 |
| Prop | Type |
|---|---|
files |
PickedFile[] |
| Prop | Type | Description | Since |
|---|---|---|---|
blob |
Blob |
The Blob instance of the file. Only available on Web. | |
data |
string |
The Base64 string representation of the data contained in the file. Is only provided if readData is set to true. |
|
duration |
number |
The duration of the video in seconds. Only available on Android and iOS. | 0.5.3 |
height |
number |
The height of the image or video in pixels. Only available on Android and iOS. | 0.5.3 |
mimeType |
string |
The mime type of the file. | |
modifiedAt |
number |
The last modified timestamp of the file in milliseconds. | 0.5.9 |
name |
string |
The name of the file. | |
path |
string |
The path of the file. Only available on Android and iOS. | |
size |
number |
The size of the file in bytes. | |
width |
number |
The width of the image or video in pixels. Only available on Android and iOS. | 0.5.3 |
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
types |
string[] |
List of accepted file types. Look at IANA Media Types for a complete list of standard media types. This option is ignored if limit is set. |
||
limit |
number |
The maximum number of files that the user can select. Setting this to 0 sets the selection limit to unlimited. Currently, only 0 and 1 are supported. |
0 |
6.0.0 |
readData |
boolean |
Whether to read the file data. Attention: Reading large files can lead to app crashes. It's therefore not recommended to use this option. Instead, use the fetch API to load the file as a blob, see this example. | false |
| Prop | Type | Description | Since |
|---|---|---|---|
path |
string |
The path to the selected directory. | 6.2.0 |
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
readData |
boolean |
Whether to read the file data. | false |
|
skipTranscoding |
boolean |
Whether to avoid transcoding, if possible. On iOS, for example, HEIC images are automatically transcoded to JPEG. Only available on iOS. | true |
|
limit |
number |
The maximum number of files that the user can select. Setting this to 0 sets the selection limit to unlimited. On Android and Web, only 0 and 1 are supported. |
0 |
5.2.0 |
ordered |
boolean |
Whether an ordered number is displayed instead of a check mark in the selection badge. Only available on iOS (15+). | false |
5.3.0 |
| Prop | Type | Description | Default | Since |
|---|---|---|---|---|
permissions |
PermissionType[] |
The permissions to request. | ["accessMediaLocation", "readExternalStorage"] |
6.1.0 |
| Prop | Type |
|---|---|
remove |
() => Promise<void> |
'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'
'accessMediaLocation' | 'readExternalStorage'
See CHANGELOG.md.
See LICENSE.
This plugin is based on the Capacitor File Picker plugin. Thanks to everyone who contributed to the project!