开始
复制一个包含安装步骤和本插件完整 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辅助设置来安装插件。将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.如果您prefer手动设置,安装插件并运行以下命令并遵循以下平台特定的说明:
bun add @capgo/capacitor-filebunx cap sync导入
标题:导入import { CapacitorFile } from '@capgo/capacitor-file';API概述
API概述requestFileSystem
请求文件系统__CAPGO_KEEP_0__概述
import { CapacitorFile, FileSystemType } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestFileSystem({ type: FileSystemType.TEMPORARY });console.log(result);resolveLocalFileSystemURL
解析本地文件系统URL__CAPGO_KEEP_0__概述
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.resolveLocalFileSystemURL({ url: 'https://example.com' });console.log(result);getFile
获取文件条目__CAPGO_KEEP_0__概述
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFile({ path: 'path/to/file' });console.log(result);getDirectory
获取目录获取目录项
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getDirectory({ path: 'path/to/file' });console.log(result);readFile
读取文件读取文件
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.readFile({ path: 'path/to/file' });console.log(result);readAsDataURL
读取为DataURL读取文件(base64)
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
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
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
读取目录读取目录内容
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
获取元数据获取文件或目录的元数据 stat()的别名
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getMetadata({ path: 'path/to/file' });console.log(result);rename
重命名重命名或移动文件或目录
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.rename({ from: 'from', to: 'to',});move
移动移动文件或目录。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.move({ from: 'from', to: 'to',});copy
contextPage/area: Capgo marketing website. Role: UI label. Seen in: page agents/[slug].astro. Message key `agents_page_copy_label` (Agents Page Copy Label).
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.copy({ from: 'from', to: 'to',});console.log(result);exists
Section titled “copy”复制文件或目录。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.exists({ path: 'path/to/file' });console.log(result);getUri
contextPage/area: Capgo marketing website. Role: UI label. Seen in: page agents/[slug].astro. Message key `agents_page_copy_label` (Agents Page Copy Label).
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getUri({ path: 'path/to/file' });console.log(result);truncate
Section titled “截断”截断文件到指定大小。
import { CapacitorFile } from '@capgo/capacitor-file';
await CapacitorFile.truncate({ path: 'path/to/file' });getDirectories
Section titled “获取目录”获取所有已知的文件系统目录。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getDirectories();console.log(result);getFreeDiskSpace
Section titled “获取可用磁盘空间”获取可用磁盘空间(以字节为单位)。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.getFreeDiskSpace();console.log(result);checkPermissions
Section titled “检查权限”检查当前文件操作权限状态。 在 Android 上,这检查外部存储权限。 在 iOS 和 web 上,这始终返回 ‘已授权’,因为不需要特殊权限。
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.checkPermissions();console.log(result);requestPermissions
请求权限文件操作权限申请
import { CapacitorFile } from '@capgo/capacitor-file';
const result = await CapacitorFile.requestPermissions();console.log(result);复制到剪贴板
类型参考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 到入口的选项。
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
写入文件选项目录项
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
写入文件结果写入文件结果
export interface WriteFileResult { /** The URI of the written file */ uri: string;}真实数据来源
真实数据来源本页面是由插件的 src/definitions.ts重新同步公共API时,重新运行同步
继续从开始
继续从开始如果您正在使用 开始使用 为计划存储和文件处理,连接它 使用@capgo/capacitor-file 为@capgo/capacitor-file中的本机能力 @capgo/capacitor-sqlite-数据存储 为@capgo/capacitor-data-storage-sqlite中的实现细节 使用@capgo/capacitor-data-storage-sqlite 为@capgo/capacitor-data-storage-sqlite中的本机能力 @capgo/capacitor文件 为@capgo/capacitor-file中的实现细节,并且 @capgo/capacitor-上传器 为@capgo/capacitor-uploader中的实现细节