スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
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.
インストール
「インストール」セクションAIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いの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.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
npm install @capgo/capacitor-filenpx cap syncインポート
「インポート」セクションimport { CapacitorFile } from '@capgo/capacitor-file';クイックスタート
「クイックスタート」セクションimport { CapacitorFile, FileSystemType } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestFileSystem({ type: FileSystemType.TEMPORARY });console.log(result);例: resolveLocalFileSystemURL
セクション「Example: resolveLocalFileSystemURL」import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.resolveLocalFileSystemURL({ url: 'file:///data/user/0/com.example.app/files/report.pdf',});console.log(result);例: getFile
「Example: getFile」セクションimport { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFile({ path: 'path/to/file' });console.log(result);よくある落とし穴
「よくある落とし穴」セクション- 権限:呼び出し
checkPermissions()その後requestPermissions()必要に応じて。 - リスナー: 画面がアンマウントされたらハンドルを削除します。
- 信頼できる情報源: 信頼
src/definitions.tsGitHub リポジトリ内。
API の概要
「API 概要」セクションrequestFileSystem
「requestFileSystem」セクションファイルシステムをリクエストします。
import { CapacitorFile, FileSystemType } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestFileSystem({ type: FileSystemType.TEMPORARY });console.log(result);resolveLocalFileSystemURL
「resolveLocalFileSystemURL」セクションファイルURLをエントリーに解決します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.resolveLocalFileSystemURL({ url: 'https://example.com' });console.log(result);getFile
「getFile」セクションファイルエントリーを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFile({ path: 'path/to/file' });console.log(result);getDirectory
「getDirectory」セクションディレクトリエントリを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getDirectory({ path: 'path/to/file' });console.log(result);readFile
「readFile」セクションファイルをテキストまたはbase64として読み込みます。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readFile({ path: 'path/to/file' });console.log(result);readAsDataURL
「readAsDataURL」セクションファイルをData URL(MIMEタイプのプレフィックス付きbase64)として読み込みます。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readAsDataURL({ path: 'path/to/file' });console.log(result);writeFile
「writeFile」セクションファイルにデータを書き込みます。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.writeFile({ path: 'path/to/file', data: 'data',});console.log(result);appendFile
「appendFile」セクションファイルにデータを追記します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.appendFile({ path: 'path/to/file', data: 'data',});console.log(result);deleteFile
「deleteFile」セクションファイルを削除します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({ path: 'path/to/file' });mkdir
「mkdir」セクションディレクトリを作成します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.mkdir({ path: 'path/to/file' });rmdir
「rmdir」セクションディレクトリを削除します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rmdir({ path: 'path/to/file' });readdir
「readdir」セクションディレクトリの内容を読み取ります。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readdir({ path: 'path/to/file' });console.log(result);stat
「stat」セクションファイルまたはディレクトリのメタデータを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.stat({ path: 'path/to/file' });console.log(result);getMetadata
「getMetadata」セクションファイルまたはディレクトリのメタデータを取得します。 stat() のエイリアスです。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getMetadata({ path: 'path/to/file' });console.log(result);rename
「rename」セクションファイルまたはディレクトリの名前を変更または移動します。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rename({ from: 'from', to: 'to',});move
「move」セクションファイルまたはディレクトリを移動します。 rename() のエイリアスです。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.move({ from: 'from', to: 'to',});copy
「copy」セクションファイルまたはディレクトリをコピーします。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.copy({ from: 'from', to: 'to',});console.log(result);exists
「exists」セクションファイルまたはディレクトリが存在するか確認します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.exists({ path: 'path/to/file' });console.log(result);getUri
「getUri」セクションファイルのURIを取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getUri({ path: 'path/to/file' });console.log(result);truncate
セクション「truncate」ファイルを指定したサイズに切り詰めます。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({ path: 'path/to/file' });getDirectories
セクション「getDirectories」既知のファイルシステムディレクトリをすべて取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getDirectories();console.log(result);getFreeDiskSpace
セクション「getFreeDiskSpace」空きディスク容量をバイト単位で取得します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFreeDiskSpace();console.log(result);checkPermissions
「checkPermissions」セクションファイル操作の現在の権限ステータスを確認します。 Androidでは外部ストレージの権限を確認します。 iOSとWebでは、特別な権限が不要なため、常に 'granted' を返します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.checkPermissions();console.log(result);requestPermissions
「requestPermissions」セクションファイル操作の権限をリクエストします。 Androidでは、アプリのプライベートディレクトリ以外の ファイルにアクセスするために必要な外部ストレージ権限をリクエストします。 iOSおよびWebでは、特別な権限は不要なため、常に 'granted' を返します。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestPermissions();console.log(result);型リファレンス
「型リファレンス」セクション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
「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;}Entry
「Entry」セクションファイルまたはディレクトリのエントリーを表します。
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
「GetFileOptions」セクションファイルを取得するためのオプション。
export interface GetFileOptions { /** Path to the file */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the file */ options?: GetOptions;}FileEntry
「FileEntry」セクションファイルのエントリーを表します。
export interface FileEntry extends Entry { isFile: true; isDirectory: false;}GetDirectoryOptions
「GetDirectoryOptions」セクションディレクトリ取得のオプション
export interface GetDirectoryOptions { /** Path to the directory */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the directory */ options?: GetOptions;}DirectoryEntry
「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;}Source of Truth
「Source Of Truth」セクションこのページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。
Getting Startedの続きを進める
「Getting Started からの続き」セクション使用している場合 スタートガイド ストレージとファイル処理を計画するには、以下と連携してください: @capgo/capacitor-file の使い方 @capgo/capacitor-file を使用して Native Build の機能を利用する場合、 @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. の実装の詳細については