Getting Started
このプラグインのインストール手順とフルマークダウンガイドのセットアッププロンプトをコピーしてください。
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.
インストール
「インストール」のセクションCapgoのAIアシストセットアップを使用してプラグインをインストールできます。次のコマンドを使用して、CapgoスキルをAIツールに追加します。
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-filebunx cap syncImport
「Import」のセクションimport { CapacitorFile } from '@capgo/capacitor-file';APIの概要
APIの概要requestFileSystem
requestFileSystemファイルシステムを要求します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestFileSystem({} as RequestFileSystemOptions);resolveLocalFileSystemURL
resolveLocalFileSystemURLURLをエントリに解決します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.resolveLocalFileSystemURL({} as ResolveURLOptions);getFile
getFileファイルエントリを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFile({} as GetFileOptions);getDirectory
getDirectoryディレクトリエントリを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectory({} as GetDirectoryOptions);readFile
「readFile」のセクションテキストまたはbase64でファイルを読み込む。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readFile({} as ReadFileOptions);readAsDataURL
「readAsDataURL」のセクションMIMEタイププレフィックス付きbase64でファイルを読み込む。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readAsDataURL({} as ReadFileOptions);writeFile
「writeFile」のセクションデータをファイルに書き込む。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.writeFile({} as WriteFileOptions);appendFile
「appendFile」のセクションファイルにデータを追加する。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.appendFile({} as WriteFileOptions);deleteFile
「ファイル削除」セクションファイルを削除します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({} as DeleteFileOptions);mkdir
「ディレクトリ作成」セクションディレクトリを作成します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.mkdir({} as MkdirOptions);rmdir
「ディレクトリ削除」セクションディレクトリを削除します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rmdir({} as DeleteDirectoryOptions);readdir
「ディレクトリ内容読み取り」セクションディレクトリの内容を読み取ります。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.readdir({} as ReaddirOptions);stat
「stat」のセクションファイルまたはディレクトリのメタデータを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.stat({} as StatOptions);getMetadata
「getMetadata」のセクションファイルまたはディレクトリのメタデータを取得します。 stat()の別名です。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getMetadata({} as StatOptions);rename
「rename」のセクションファイルまたはディレクトリを名前変更または移動します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rename({} as RenameOptions);move
「move」のセクションファイルまたはディレクトリを移動します。 rename()の別名です。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.move({} as RenameOptions);copy
「コピー」のセクションファイルまたはディレクトリをコピーします。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.copy({} as CopyOptions);exists
「存在」のセクションファイルまたはディレクトリが存在するかどうかを確認します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.exists({} as ExistsOptions);getUri
「URI取得」のセクションファイルのURIを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getUri({} as GetUriOptions);truncate
「サイズ指定」ファイルを指定されたサイズに短縮します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({} as TruncateOptions);getDirectories
「getDirectories」セクションファイルシステムのすべてのディレクトリを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectories();getFreeDiskSpace
「getFreeDiskSpace」セクションバイト単位の空きディスクスペースを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFreeDiskSpace();checkPermissions
「checkPermissions」セクションファイル操作の現在の許可状態を確認します。 Androidでは、外部ストレージの許可を確認します。 iOSとWebでは、特別な許可が必要ないため、常に「許可」が返されます。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.checkPermissions();requestPermissions
「requestPermissions」セクションファイル操作の許可を要求します。 Androidでは、外部ストレージの許可が必要なファイルをアクセスするために必要な許可を要求します。 iOSとWebでは、特別な許可が必要ないため、常に「許可」が返されます。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestPermissions();型の参照
「型の参照」のセクションRequestFileSystemOptions
「RequestFileSystemOptions」のセクションファイル システムを要求するためのオプション
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;}FileSystem
「ファイル システム」のセクションファイル システムを表します。
export interface FileSystem { /** The name of the file system */ name: string; /** The root directory of the file system */ root: DirectoryEntry;}ResolveURLOptions
「ResolveURLOptions」のセクション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
Section titled “GetFileOptions”ファイルを取得するためのオプション
export interface GetFileOptions { /** Path to the file */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the file */ options?: GetOptions;}FileEntry
Section titled “ファイルエントリ”ファイルエントリを表します。
export interface FileEntry extends Entry { isFile: true; isDirectory: false;}GetDirectoryOptions
Section titled “GetDirectoryOptions”ディレクトリを取得するためのオプション
export interface GetDirectoryOptions { /** Path to the directory */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the directory */ options?: GetOptions;}DirectoryEntry
ディレクトリエントリディレクトリエントリを表します。
export interface DirectoryEntry extends Entry { isFile: false; isDirectory: true;}ReadFileOptions
セクション「ReadFileOptions」ファイルを読み込むためのオプション
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
セクション「ReadFileResult」ファイルを読み込んだ結果
export interface ReadFileResult { /** File contents as string (text) or base64 (binary) */ data: string;}WriteFileOptions
セクション「WriteFileOptions」ファイルを書き込むためのオプション
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
WriteFileResultファイルの書き込み結果
export interface WriteFileResult { /** The URI of the written file */ uri: string;}このページはプラグインの src/definitions.tsから生成されています。 公開 API のアップストリームで変更が発生した場合、再度同期を実行してください。
Getting Startedから続ける
Section titled “Getting Startedから続ける”あなたが Getting Started を使用してストレージとファイルの取り扱いを計画している場合、それを Using @capgo/capacitor-file for the native capability in Using @capgo/capacitor-file, @capgo/capacitor-data-storage-sqlite for the implementation detail in @capgo/capacitor-data-storage-sqlite, Using @capgo/capacitor-data-storage-sqlite for the native capability in Using @capgo/capacitor-data-storage-sqlite, @capgo/capacitor-file for the implementation detail in @capgo/capacitor-file, and @capgo/capacitor-uploader for the implementation detail in @capgo/capacitor-uploader.