Package Exports
- @capawesome/capacitor-file-picker
- @capawesome/capacitor-file-picker/dist/esm/index.js
- @capawesome/capacitor-file-picker/dist/plugin.cjs.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@capawesome/capacitor-file-picker) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
File Picker
@capawesome/capacitor-file-picker
Capacitor plugin that allows the user to select a file.
Maintainers
| Maintainer | GitHub | Social |
|---|---|---|
| Robin Genz | robingenz | @robin_genz |
Sponsors
This is an MIT-licensed open source project. It can grow thanks to the support by these awesome people. If you'd like to join them, please read more here.
Installation
npm install @capawesome/capacitor-file-picker
npx cap syncConfiguration
No configuration required for this plugin.
Demo
A working example can be found here: robingenz/capacitor-plugin-demo
Usage
import { FilePicker } from '@capawesome/capacitor-file-picker';
const pickFiles = async () => {
const result = await FilePicker.pickFiles({
types: ['image/png'],
multiple: true,
});
};
const pickImages = async () => {
const result = await FilePicker.pickImages({
multiple: true,
});
};
const pickMedia = async () => {
const result = await FilePicker.pickMedia({
multiple: true,
});
};
const pickVideos = async () => {
const result = await FilePicker.pickVideos({
multiple: true,
});
};
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);
}
};API
pickFiles(...)
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(...)
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(...)
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(...)
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
Interfaces
PickFilesResult
| Prop | Type |
|---|---|
files |
File[] |
File
| 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 milliseconds. 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. | |
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 |
PickFilesOptions
| Prop | Type | Description | Default |
|---|---|---|---|
types |
string[] |
List of accepted file types. Look at IANA Media Types for a complete list of standard media types. This option cannot be used with multiple: true on Android. |
|
multiple |
boolean |
Whether multiple files may be selected. | false |
readData |
boolean |
Whether to read the file data. | false |
PickMediaOptions
| Prop | Type | Description | Default |
|---|---|---|---|
multiple |
boolean |
Whether multiple files may be selected. | false |
readData |
boolean |
Whether to read the file data. | false |
Type Aliases
PickedFile
PickImagesOptions
PickImagesResult
PickMediaResult
PickVideosOptions
PickVideosResult
Changelog
See CHANGELOG.md.
License
See LICENSE.