Vai al contenuto

Getting Started

Questo contenuto non è ancora disponibile nella tua lingua.

Terminal window
bun add @capgo/capacitor-file-picker
bunx cap sync
import { CapgoFilePicker } from '@capgo/capacitor-file-picker';

Pick one or more files from the device.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const result = await CapgoFilePicker.pickFiles({
types: ['application/pdf', 'image/*'],
limit: 5,
readData: false
});
console.log('Picked files:', result.files);

Pick one or more images from the gallery. Android/iOS only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const result = await CapgoFilePicker.pickImages({
limit: 10,
readData: false
});
console.log('Picked images:', result.files);

Pick one or more videos from the gallery. Android/iOS only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const result = await CapgoFilePicker.pickVideos({
limit: 3,
skipTranscoding: true
});
console.log('Picked videos:', result.files);

Pick one or more images or videos from the gallery. Android/iOS only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const result = await CapgoFilePicker.pickMedia({
limit: 5,
readData: true
});
console.log('Picked media:', result.files);

Pick a directory from the device. Android/iOS only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const result = await CapgoFilePicker.pickDirectory();
console.log('Selected directory:', result.path);

Convert a HEIC image to JPEG format. iOS only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const result = await CapgoFilePicker.convertHeicToJpeg({
path: '/path/to/image.heic',
quality: 0.9
});
console.log('Converted file:', result.path);

Copy a file to a new location.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
await CapgoFilePicker.copyFile({
from: '/source/file.pdf',
to: '/destination/file.pdf',
overwrite: true
});

Check permissions for reading files. Android only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const status = await CapgoFilePicker.checkPermissions();
console.log('Read permission:', status.readExternalStorage);

Request permissions for reading files. Android only.

import { CapgoFilePicker } from '@capgo/capacitor-file-picker';
const status = await CapgoFilePicker.requestPermissions();
if (status.readExternalStorage === 'granted') {
console.log('Permission granted');
}

Options for picking files.

export interface PickFilesOptions {
/**
* List of accepted MIME types or file extensions.
* On iOS, only MIME types are supported.
* Examples: ['image/*'], ['application/pdf'], ['.pdf', '.doc']
*/
types?: string[];
/**
* Maximum number of files to pick.
* Set to 0 for unlimited (platform default).
* @default 0
*/
limit?: number;
/**
* Whether to read the file data as base64.
* Note: Reading large files may cause memory issues.
* @default false
*/
readData?: boolean;
}

Result of picking files.

export interface PickFilesResult {
/** Array of picked files */
files: PickedFile[];
}

Options for picking media (images/videos).

export interface PickMediaOptions {
/**
* Maximum number of files to pick.
* Set to 0 for unlimited (platform default).
* @default 0
*/
limit?: number;
/**
* Whether to read the file data as base64.
* Note: Reading large files may cause memory issues.
* @default false
*/
readData?: boolean;
/**
* iOS only: Skip transcoding of videos.
* @default false
*/
skipTranscoding?: boolean;
/**
* iOS 15+ only: Show ordered selection badges.
* @default false
*/
ordered?: boolean;
}

Result of picking a directory.

export interface PickDirectoryResult {
/** The path to the selected directory */
path: string;
}

Options for converting HEIC to JPEG.

export interface ConvertHeicToJpegOptions {
/** The path to the HEIC file to convert */
path: string;
/**
* The compression quality for JPEG (0.0 - 1.0).
* @default 0.9
*/
quality?: number;
}

Result of HEIC to JPEG conversion.

export interface ConvertHeicToJpegResult {
/** The path to the converted JPEG file */
path: string;
}

Options for copying a file.

export interface CopyFileOptions {
/** Source file path */
from: string;
/** Destination file path */
to: string;
/**
* Whether to overwrite if destination exists.
* @default false
*/
overwrite?: boolean;
}

Permission status for file access.

export interface PermissionStatus {
/** Whether permission to read media files is granted */
readExternalStorage: PermissionState;
/** Whether permission to access media location is granted */
accessMediaLocation?: PermissionState;
}

Listener callback for picker dismissed event.

export type PickerDismissedListener = (event: null) => void;

Represents a picked file.

export interface PickedFile {
/** The name of the file */
name: string;
/** The path to the file */
path?: string;
/** The MIME type of the file */
mimeType: string;
/** The size of the file in bytes */
size: number;
/**
* The base64 encoded data of the file.
* Only present if readData was true.
*/
data?: string;
/**
* The Blob instance of the file.
* Web only.
*/
blob?: Blob;
/** Width in pixels (images/videos only) */
width?: number;
/** Height in pixels (images/videos only) */
height?: number;
/** Duration in seconds (videos only) */
duration?: number;
/** Last modified timestamp in milliseconds */
modifiedAt?: number;
}

Permission state values.

export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';

This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.