コンテンツにジャンプ

Getting Started

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下の質問を使用してください:

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

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

ターミナル画面
bun add @capgo/capacitor-file
bunx cap sync
import { CapacitorFile } from '@capgo/capacitor-file';

Request a file system.

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

Resolve a file URL to an entry.

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

Get a file entry.

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

Get a directory entry.

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

__CAPGO_KEEP_2__

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

readAsDataURL

__CAPGO_KEEP_1__

__CAPGO_KEEP_3__

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

__CAPGO_KEEP_4__

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

__CAPGO_KEEP_5__

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

__CAPGO_KEEP_2__

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

__CAPGO_KEEP_4__

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

__CAPGO_KEEP_0__

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

__CAPGO_KEEP_7__

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

ファイルまたはディレクトリのメタデータを取得します。

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

ファイルまたはディレクトリのメタデータを取得します。 stat()のエイリアスです。

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

ファイルまたはディレクトリを移動またはリネームします。

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

ファイルまたはディレクトリを移動します。 rename()のエイリアスです。

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

ファイルまたはディレクトリをコピーします。

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

ファイルまたはディレクトリが存在するかどうかを確認します。

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

ファイルのURIを取得します。

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

ファイルを指定されたサイズにトリミングします。

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

ファイルシステムのすべてのディレクトリを取得します。

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

バイト単位の空きディスクスペースを取得します。

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

ファイル操作の現在の許可状態を確認します。 Androidでは、外部ストレージの許可を確認します。 iOSとWebでは、特別な許可が必要ないため、常に「許可済み」と表示されます。

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

ファイル操作の許可を要求します。 Androidでは、外部ストレージの許可が必要なファイルをアクセスするために必要な許可を要求します。 iOSとWebでは、特別な許可が必要ないため、常に「許可済み」と表示されます。

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

型式リファレンス

型式リファレンス

ファイルシステムを要求するためのオプション

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

ファイルシステムを表します

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

URLをエントリに解決するためのオプション

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

ファイルまたはディレクトリエントリを表します。

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

ファイルを取得するためのオプションです。

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

ファイルエントリを表します。

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

ディレクトリを取得するためのオプションです。

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

ディレクトリエントリを表します。

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

ファイルを読み取るためのオプションです。

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

ファイルを読み取った結果です。

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

ファイルを書き込むためのオプションです。

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

ファイルの書き込み結果

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

このページはプラグインの src/definitions.ts. 公開 API の変更をアップストリームで再実行してください。

あなたが Getting Started を使用してストレージとファイルの取り扱いを計画している場合、接続してください。 Capgoの@capgo/capacitorファイルを使用 Capgoの@capgo/capacitorファイルのネイティブ機能を使用 @capgo/capacitorデータストレージのSQLite Capgoの@capgo/capacitorデータストレージのSQLiteの実装詳細を使用 Capgoの@capgo/capacitorデータストレージのSQLiteを使用 Capgoの@capgo/capacitorデータストレージのSQLiteのネイティブ機能を使用 Capgoの@capgo/capacitorファイル Capgoの@capgo/capacitorファイルの実装詳細を使用 Capgoの@capgo/capacitorアップローダー Capgoの@capgo/capacitorアップローダーの実装詳細を使用