Capacitor plugin that allows the user to select a file.
npm install @capawesome/capacitor-file-picker
npx cap sync
No configuration required for this plugin.
A working example can be found here: robingenz/capacitor-plugin-demo
import { FilePicker } from '@capawesome/capacitor-file-picker';
const pickFiles = async () => {
const result = await FilePicker.pickFiles({
types: ['image/png'],
});
};
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 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);
}
};
convertHeicToJpeg(...)
pickFiles(...)
pickImages(...)
pickMedia(...)
pickVideos(...)
addListener('pickerDismissed', ...)
removeAllListeners()
- Interfaces
- Type Aliases
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
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>
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
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 |
---|---|---|---|
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 |
---|---|
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. | false |
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 |
---|---|
remove |
() => Promise<void> |
See CHANGELOG.md.
See LICENSE.
This plugin is based on the Capacitor File Picker plugin. Thanks to everyone who contributed to the project!