Passer à la navigation

Démarrage

GitHub

Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA à l'aide de la commande suivante :

Fenêtre de terminal
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Ensuite, utilisez 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 :

Fenêtre de terminal
bun add @capgo/capacitor-file
bunx cap sync
import { CapacitorFile } from '@capgo/capacitor-file';

Demandez un système de fichiers.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestFileSystem({} as RequestFileSystemOptions);

Résolvez une URL de fichier en entrée.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.resolveLocalFileSystemURL({} as ResolveURLOptions);

Obtenez une entrée de fichier.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFile({} as GetFileOptions);

Obtenez une entrée de répertoire.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectory({} as GetDirectoryOptions);

Lire un fichier en texte ou base64.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readFile({} as ReadFileOptions);

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);

Écrire des données dans un fichier.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.writeFile({} as WriteFileOptions);

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 les contenus du répertoire.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readdir({} as ReaddirOptions);

Obtenez les métadonnées d'un fichier ou d'un répertoire.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.stat({} as StatOptions);

Obtenez 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éplacez 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érifiez si un fichier ou un répertoire existe.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.exists({} as ExistsOptions);

Obtenez l'URI pour un fichier.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getUri({} as GetUriOptions);

Tronquez un fichier jusqu'à une taille spécifiée.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({} as TruncateOptions);

Obtenez toutes les répertoires de système de fichiers connus.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectories();

Obtenez l'espace disque libre en octets.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFreeDiskSpace();

Vérifiez l'état actuel des permissions pour les opérations de fichiers. Sur Android, cela vérifie les permissions d'accès aux fichiers de stockage externe. Sur iOS et web, cela retourne toujours ‘granted’ car aucune permission spéciale n'est nécessaire.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.checkPermissions();

Demandez les permissions pour les opérations de fichiers. Sur Android, cela demande les permissions d'accès aux fichiers de stockage externe nécessaires pour accéder aux fichiers en dehors des répertoires privés de l'application. Sur iOS et web, cela retourne toujours ‘granted’ car aucune permission spéciale n'est nécessaire.

import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestPermissions();

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;
}

Options pour résoudre une URL en entrée.

export interface ResolveURLOptions {
/** The URL to resolve (file:// or cdvfile://) */
url: string;
}

Représente un élément 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;
}

Options pour obtenir 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;
}

Options pour obtenir un répertoire.

export interface GetDirectoryOptions {
/** Path to the directory */
path: string;
/** Base directory */
directory?: Directory;
/** Options for creating the directory */
options?: GetOptions;
}

Représente une entrée de répertoire.

export interface DirectoryEntry extends Entry {
isFile: false;
isDirectory: true;
}

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;
}

Résultat de la lecture d'un fichier.

export interface ReadFileResult {
/** File contents as string (text) or base64 (binary) */
data: string;
}

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;
}

Résultat de l'écriture d'un fichier.

export interface WriteFileResult {
/** The URI of the written file */
uri: string;
}

Cette page est générée à partir du plugin’s src/definitions.tsRe-faire la synchronisation lorsque le public API change en amont.

Si vous utilisez Getting Started pour planifier le stockage et la gestion des fichiers, connectez-le avec Utiliser @capgo/capacitor-file pour la capacité native dans Utiliser @capgo/capacitor-file, @capgo/capacitor-stockage-de-données-sqlite pour le détail d'implémentation dans @capgo/capacitor-stockage-de-données-sqlite, En utilisant @capgo/capacitor-stockage-de-données-sqlite pour la capacité native dans En utilisant @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.