コンテンツにスキップ

Getting Started

GitHub

AI-Assisted セットアップを使用してプラグインをインストールできます。AI ツールに Capgo スキルを追加するには、以下のコマンドを実行してください。

ターミナルウィンドウ
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.

Manual Setupを使用する場合は、プラットフォーム固有の指示に従う前に、以下のコマンドを実行してプラグインをインストールしてください:

ターミナルウィンドウ
bun add @capgo/capacitor-file
bunx cap sync
import { CapacitorFile } from '@capgo/capacitor-file';

__CAPGO_KEEP_0__を要求します。

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

URLをエントリに解決します。

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

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

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

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

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

テキストまたはbase64でファイルを読みます。

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

MIMEタイププレフィックス付きbase64でファイルを読みます。

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

データをファイルに書き込みます。

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

データをファイルに追加します。

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

ファイルを削除します。

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

ディレクトリを作成します。

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

ディレクトリを削除します。

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

ディレクトリの内容を読みます。

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

タイプ リファレンス

Type Reference

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

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

GetFileOptions

__CAPGO_KEEP_1__

__CAPGO_KEEP_2__

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

__CAPGO_KEEP_3__

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

GetDirectoryOptions

__CAPGO_KEEP_1__

__CAPGO_KEEP_4__

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

DirectoryEntry

__CAPGO_KEEP_5__

__CAPGO_KEEP_0__

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.tsAPIがアップストリームで変更されたら、再度同期を実行してください。

Getting Startedから続けて

Getting Startedから続けて

Capgoを使用している場合 Getting Started Capgoを使用している場合、ストレージとファイルの取り扱いを計画するには、Capgoを__CAPGO_KEEP_0__と__CAPGO_KEEP_1__-file Capgoを使用している場合、Capgoのnative capabilityをcapgoとcapacitor-file for the native capability in Using @capgo/capacitor-file, @capgo/capacitor-data-storage-sqlite 実装詳細については @capgo/capacitor-data-storage-sqlite を参照してください。 @capgo/capacitor-data-storage-sqlite を使用します。 @capgo/capacitor-data-storage-sqlite を使用したネイティブ機能については @capgo/capacitor-file 実装詳細については @capgo/capacitor-file を参照してください。 @capgo/capacitor-uploader 実装詳細については @capgo/capacitor-uploader を参照してください。