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.
インストール
「インストール」のセクション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-filebunx cap syncインポート
「インポート」のセクションimport { CapacitorFile } from '@capgo/capacitor-file';requestFileSystem
Section titled “requestFileSystem”Request a file system.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestFileSystem({} as RequestFileSystemOptions);resolveLocalFileSystemURL
Section titled “resolveLocalFileSystemURL”Resolve a file URL to an entry.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.resolveLocalFileSystemURL({} as ResolveURLOptions);getFile
Section titled “getFile”Get a file entry.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFile({} as GetFileOptions);getDirectory
Section titled “getDirectory”Get a directory entry.
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectory({} as GetDirectoryOptions);readFile
__CAPGO_KEEP_1____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);writeFile
__CAPGO_KEEP_1____CAPGO_KEEP_4__
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.writeFile({} as WriteFileOptions);appendFile
__CAPGO_KEEP_1____CAPGO_KEEP_5__
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.appendFile({} as WriteFileOptions);deleteFile
__CAPGO_KEEP_1____CAPGO_KEEP_2__
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({} as DeleteFileOptions);mkdir
__CAPGO_KEEP_3____CAPGO_KEEP_4__
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.mkdir({} as MkdirOptions);rmdir
__CAPGO_KEEP_5____CAPGO_KEEP_0__
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rmdir({} as DeleteDirectoryOptions);readdir
__CAPGO_KEEP_0____CAPGO_KEEP_7__
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
__CAPGO_KEEP_1__のセクションファイルシステムのすべてのディレクトリを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getDirectories();getFreeDiskSpace
__CAPGO_KEEP_2__のセクションバイト単位の空きディスクスペースを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.getFreeDiskSpace();checkPermissions
__CAPGO_KEEP_3__のセクションファイル操作の現在の許可状態を確認します。 Androidでは、外部ストレージの許可を確認します。 iOSとWebでは、特別な許可が必要ないため、常に「許可済み」と表示されます。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.checkPermissions();requestPermissions
__CAPGO_KEEP_4__のセクションファイル操作の許可を要求します。 Androidでは、外部ストレージの許可が必要なファイルをアクセスするために必要な許可を要求します。 iOSとWebでは、特別な許可が必要ないため、常に「許可済み」と表示されます。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.requestPermissions();型式リファレンス
型式リファレンス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
URLをエントリに解決するためのオプション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 “FileEntry”ファイルエントリを表します。
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
ファイル読み取りのオプションのセクションファイルを読み取るためのオプションです。
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
ファイル読み取りの結果のセクションファイルを読み取った結果です。
export interface ReadFileResult { /** File contents as string (text) or base64 (binary) */ data: string;}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
Section titled “WriteFileResult”ファイルの書き込み結果
export interface WriteFileResult { /** The URI of the written file */ uri: string;}このページはプラグインの src/definitions.ts. 公開 API の変更をアップストリームで再実行してください。
Getting Started から続けて
Section titled “Getting Started から続けて”あなたが 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アップローダーの実装詳細を使用