Capgo __CAPGO_KEEP_0__ リポジトリ
インストールステップとこのプラグインのフルマークダウンガイドを含むセットアップコマンドをコピーしてください。
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-Assisted Setupを使用してプラグインをインストールできます。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-filebunx cap syncインポート
「インポート」のセクションimport { CapacitorFile } from '@capgo/capacitor-file';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ファイルをデータURL (base64 MIMEタイププレフィックス)として読み取ります。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readAsDataURL({ path: 'path/to/file' });console.log(result);writeFile
「ファイルを書き込む」セクションファイルにデータを書き込む。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.writeFile({ path: 'path/to/file', data: 'data',});console.log(result);appendFile
「ファイルを追記する」セクションファイルにデータを追記する。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.appendFile({ path: 'path/to/file', data: 'data',});console.log(result);deleteFile
「ファイルを削除する」セクションファイルを削除する。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.deleteFile({ path: 'path/to/file' });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の場合、特別な許可が必要ないため常に「許可済み」と表示されます。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.checkPermissions();console.log(result);requestPermissions
セクション「requestPermissions」ファイル操作の許可を要求します。 Androidの場合、外部ストレージの許可を要求して アプリのプライベートディレクトリ外のファイルにアクセスする必要があります。 iOSとWebの場合、特別な許可が必要ないため常に「許可済み」と表示されます。
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
「ファイルシステム」のセクションファイルシステムを表します。
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;}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
「ファイルを取得するためのオプション」のセクションファイルを取得するためのオプション
export interface GetFileOptions { /** Path to the file */ path: string; /** Base directory */ directory?: Directory; /** Options for creating the file */ options?: GetOptions;}FileEntry
「ファイルエントリ」のセクションファイルエントリを表します。
export interface FileEntry extends Entry { isFile: true; isDirectory: false;}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
「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
セクションのタイトル「続けてGetting Started」あなたが使用している場合 Getting Started ストレージとファイルのハンドリングを計画するために使用している場合、接続してください。 @capgo/capacitorファイルを使用します。 Using @capgo/capacitor-file @capgo/capacitor-データストレージ-SQLite for the implementation detail in @capgo/capacitor-data-storage-sqlite Using @capgo/capacitor-data-storage-sqlite Capgoのネイティブ機能である@capgo/capacitor-data-storage-sqliteの使用 @capgo/capacitorファイル Capgoの実装詳細である@capgo/capacitor-fileの使用 @capgo/capacitorファイルアップローダ @capgo/capacitor-アップローダーの実装詳細のため。