Zum Inhalt springen

Anleitung

GitHub

Sie können unser AI-gestütztes Setup verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten zu Ihrem AI-Tool hinzu, indem Sie folgenden Befehl ausführen:

Terminalfenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Verwenden Sie dann folgende Anweisung:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-file` plugin in my project.

Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und die darunterstehenden plattform-spezifischen Anweisungen befolgen:

Terminalfenster
bun add @capgo/capacitor-file
bunx cap sync
import { CapacitorFile } from '@capgo/capacitor-file';

Einen Dateisystem anfordern.

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

Eine Datei-URL auf eine Eingabe auflösen.

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

Ein Dateieintrag erhalten.

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

Ein Verzeichniseintrag erhalten.

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

Ein Datei als Text oder Base64 lesen.

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

Eine Datei als Daten-URL (Base64 mit MIME-Typ-Präfix) lesen.

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

Daten in eine Datei schreiben.

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

Daten zu einer Datei anhängen.

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

Ein Datei löschen.

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

Ein Verzeichnis erstellen.

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

Ein Verzeichnis löschen.

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

Inhalt des Verzeichnisses lesen.

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

Datei- oder Verzeichnismetadaten abrufen.

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

Datei- oder Verzeichnismetadaten abrufen. Alias für stat().

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

Datei oder Verzeichnis umbenennen.

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

Datei oder Verzeichnis verschieben. Alias für rename().

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

Einen Datei- oder Verzeichnisbaum kopieren.

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

Überprüfen, ob eine Datei oder ein Verzeichnis existiert.

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

Ermitteln Sie die URI einer Datei.

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

Eine Datei auf eine bestimmte Größe trancieren.

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

Alle bekannten Dateisystemverzeichnisse abrufen.

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

Die freie Festplattenfläche in Bytes abrufen.

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

Überprüfen Sie den aktuellen Berechtigungsstatus für Dateibearbeitungen. Bei Android- Geräten prüft dies die externen Speicherberechtigungen. Bei iOS- und Web- Geräten wird immer ‘erlaubt’ zurückgegeben, da keine besonderen Berechtigungen erforderlich sind.

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

Berechtigungen für Dateibearbeitungen anfordern. Bei Android-Geräten werden die externen Speicherberechtigungen benötigt, um Daten außerhalb der privaten Verzeichnisse des Apps zuzugreifen. Bei iOS- und Web-Geräten wird immer ‘erlaubt’ zurückgegeben, da keine besonderen Berechtigungen erforderlich sind.

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

Optionen für die Anforderung eines Dateisystems.

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

Darstellt ein Dateisystem.

export interface FileSystem {
/** The name of the file system */
name: string;
/** The root directory of the file system */
root: DirectoryEntry;
}

Optionen für die Auflösung einer URL zu einem Eintrag.

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

Darstellt einen Datei- oder Verzeichniseintrag.

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

Optionen zum Abrufen eines Dateisystems.

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

Darstellt eine Dateieinheit.

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

Optionen zum Abrufen eines Verzeichnisses.

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

Darstellt eine Verzeichniseinheit.

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

Optionen für das Lesen eines Dateisystems.

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

Ergebnis der Dateiläsung.

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

Optionen für das Schreiben eines Dateisystems.

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

Ergebnis der Dateischreibung.

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

Diese Seite wird aus dem Plugin generiert. src/definitions.tsRe-run die Synchronisation, wenn die öffentliche API upstream geändert wird.

Wenn Sie Cloudflare verwenden Getting Started um den Speicher und die Dateimanagement zu planen, verbinden Sie es mit Mit @capgo/capacitor-file für die native Fähigkeit in Mit @capgo/capacitor-file, @capgo/capacitor-Speicherplatz-SQLite für die Implementierungsdetails in @capgo/capacitor-Speicherplatz-SQLite, Mit @capgo/capacitor-Speicherplatz-SQLite für die native Fähigkeit in Mit @capgo/capacitor-Speicherplatz-SQLite, @capgo/capacitor-Datei für die Implementierungsdetails in @capgo/capacitor-Datei und @capgo/capacitor-Uploader für die Implementierungsdetails in @capgo/capacitor-Uploader.