Getting Started
Copiez une invite de commande avec les étapes d'installation et la guide markdown complète pour ce plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-file`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/file/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installer
Section intitulée « Installer »Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA en utilisant la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsUtilisez ensuite la prompt suivante :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-file` plugin in my project.Si vous préférez la configuration manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :
bun add @capgo/capacitor-filebunx cap syncImporter
Section intitulée « Importer »import { CapacitorFile } from '@capgo/capacitor-file';API Vue d'ensemble
Section intitulée “API Présentation”requestFileSystem
Section intitulée “requestFileSystem”Demander un système de fichiers.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestFileSystem({} as RequestFileSystemOptions);resolveLocalFileSystemURL
Section intitulée “resolveLocalFileSystemURL”Résoudre une URL de fichier en entrée.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.resolveLocalFileSystemURL({} as ResolveURLOptions);getFile
Section intitulée “getFile”Obtenir une entrée de fichier.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFile({} as GetFileOptions);getDirectory
Section intitulée “getDirectory”Obtenir une entrée de répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectory({} as GetDirectoryOptions);Lire un fichier en texte ou en base64.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readFile({} as ReadFileOptions);readAsDataURL
Section intitulée « lireCommeDataURL »Lire un fichier sous forme de URL de données (base64 avec préfixe MIME).
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readAsDataURL({} as ReadFileOptions);writeFile
Section intitulée « écrireFichier »Écrire des données dans un fichier.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.writeFile({} as WriteFileOptions);appendFile
Section intitulée « ajouterFichier »Ajouter des données à un fichier.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.appendFile({} as WriteFileOptions);Supprimer un fichier.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({} as DeleteFileOptions);Créer un répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.mkdir({} as MkdirOptions);Supprimer un répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rmdir({} as DeleteDirectoryOptions);Lire le contenu du répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readdir({} as ReaddirOptions);Obtenir les métadonnées d'un fichier ou d'un répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.stat({} as StatOptions);getMetadata
Section intitulée « getMetadata »Obtenir les métadonnées d'un fichier ou d'un répertoire. Alias pour stat().
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getMetadata({} as StatOptions);Renommer ou déplacer un fichier ou un répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rename({} as RenameOptions);Déplacer un fichier ou un répertoire. Alias pour rename().
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.move({} as RenameOptions);Copier un fichier ou un répertoire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.copy({} as CopyOptions);Vérifier si un fichier ou un répertoire existe.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.exists({} as ExistsOptions);Obtenir l'URI pour un fichier.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getUri({} as GetUriOptions);truncate
Section intitulée « tronquer »Tronquer un fichier jusqu'à une taille spécifiée.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({} as TruncateOptions);getDirectories
Section intitulée “getDirectories”Obtenir tous les répertoires du système de fichiers.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectories();getFreeDiskSpace
Section intitulée “getFreeDiskSpace”Obtenir l'espace disque libre en octets.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFreeDiskSpace();checkPermissions
Section intitulée “checkPermissions”Vérifier l'état actuel des permissions pour les opérations de fichiers. Sur Android, cela vérifie les permissions d'accès aux données externes. Sur iOS et web, cela renvoie toujours ‘accordé’ car aucune permission spéciale n'est nécessaire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.checkPermissions();requestPermissions
Section intitulée “requestPermissions”Demander les permissions pour les opérations de fichiers. Sur Android, cela demande les permissions d'accès aux données externes nécessaires pour accéder aux fichiers en dehors des répertoires privés de l'application. Sur iOS et web, cela renvoie toujours ‘accordé’ car aucune permission spéciale n'est nécessaire.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestPermissions();Référence de type
Section intitulée « Référence de type »RequestFileSystemOptions
Section intitulée « Options de demande de système de fichiers »Options pour demander un système de fichiers.
export interface RequestFileSystemOptions { /** The type of file system to request */ type: FileSystemType; /** Requested size in bytes (may not be enforced on all platforms) */ size?: number;}Représente un système de fichiers.
export interface FileSystem { /** The name of the file system */ name: string; /** The root directory of the file system */ root: DirectoryEntry;}ResolveURLOptions
Section intitulée « Options de résolution d'URL »Options pour résoudre une URL à un élément.
export interface ResolveURLOptions { /** The URL to resolve (file:// or cdvfile://) */ url: string;}Représente une entrée de fichier ou de répertoire.
export interface Entry { /** True if this is a file */ isFile: boolean; /** True if this is a directory */ isDirectory: boolean; /** The name of the file or directory */ name: string; /** The full path relative to the filesystem root */ fullPath: string; /** The native file:// URI */ nativeURL: string;}GetFileOptions
Section intitulée “Options de récupération de fichier”Options pour récupérer un fichier.
export interface GetFileOptions { /** Path to the file */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the file */ options?: GetOptions;}Représente une entrée de fichier.
export interface FileEntry extends Entry { isFile: true; isDirectory: false;}GetDirectoryOptions
Section intitulée “Options de récupération de répertoire”Options pour récupérer un répertoire.
export interface GetDirectoryOptions { /** Path to the directory */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the directory */ options?: GetOptions;}DirectoryEntry
Section intitulée “DirectoryEntry”Représente une entrée de répertoire.
export interface DirectoryEntry extends Entry { isFile: false; isDirectory: true;}ReadFileOptions
Section intitulée “ReadFileOptions”Options pour lire un fichier.
export interface ReadFileOptions { /** Path to the file */ path: string; /** Base directory */ directory?: Directory; /** Encoding for text files (omit for binary/base64) */ encoding?: Encoding; /** Byte offset to start reading from (default: 0) */ offset?: number; /** Number of bytes to read (default: read to end of file) */ length?: number;}ReadFileResult
Section intitulée “ReadFileResult”Résultat de la lecture d'un fichier.
export interface ReadFileResult { /** File contents as string (text) or base64 (binary) */ data: string;}WriteFileOptions
Section intitulée “WriteFileOptions”Options pour écrire un fichier.
export interface WriteFileOptions { /** Path to the file */ path: string; /** Base directory */ directory?: Directory; /** Data to write (string for text, base64 for binary) */ data: string; /** Encoding for text files */ encoding?: Encoding; /** If true, append to existing file instead of overwriting */ append?: boolean; /** Create intermediate directories if they don't exist */ recursive?: boolean; /** Byte position to start writing at (for random access writes). If not specified, writes from beginning or appends based on 'append' flag */ position?: number;}WriteFileResult
Titre de la section « Écrire le résultat du fichier »Résultat de l'écriture d'un fichier.
export interface WriteFileResult { /** The URI of the written file */ uri: string;}Source de vérité
Titre de la section « Source de vérité »Cette page est générée à partir du plugin’s src/definitions.ts. Re-run la synchronisation lorsque les modifications publiques API sont apportées en amont.
Continuez de la section « Commencer »
Titre de la section « Continuez de la section « Commencer » »Si vous utilisez Commencer pour planifier le stockage et la gestion des fichiers, connectez-l’avec Utilisation de @capgo/capacitor-fichier pour la capacité native dans Utilisation de @capgo/capacitor-fichier @capgo/capacitor-stockage-de-données-sqlite pour le détail d'implémentation dans @capgo/capacitor-stockage-de-données-sqlite Utilisation de @capgo/capacitor-stockage-de-données-sqlite pour la capacité native dans Utilisation de @capgo/capacitor-stockage-de-données-sqlite @capgo/capacitor-fichier pour le détail d'implémentation dans @capgo/capacitor-fichier, et @capgo/capacitor-téléchargeur pour le détail d'implémentation dans @capgo/capacitor-téléchargeur.