はじめに
インストール手順とこのプラグインのフルマークダウンガイドを含むセットアップの質問をコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-file-sharer`
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-sharer/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-sharer` plugin in my project.Manualセットアップを使用する場合は、以下のコマンドを実行してください。プラットフォーム固有の指示に従ってください。
bun add @capgo/capacitor-file-sharerbunx cap syncインポート
「インポート」のセクションimport { FileSharer } from '@capgo/capacitor-file-sharer';Base64形式のファイルを共有
「Base64形式のファイルを共有」のセクションimport { FileSharer } from '@capgo/capacitor-file-sharer';
await FileSharer.share({ filename: 'report.pdf', contentType: 'application/pdf', base64Data: reportBase64, title: 'Quarterly report', text: 'Attached report',});base64Data Base64形式の文字列またはデータURL(例えば data:application/pdf;base64,....
ローカルファイルを共有
「ローカルファイルを共有」のセクションawait FileSharer.share({ filename: 'export.zip', contentType: 'application/zip', path: fileUri,});ネイティブ実装ではローカルパス、URL、Android URI、または file:// URL content:// Capacitor _capacitor_file_ URL
ファイルを保存
セクション「ファイルを保存」const result = await FileSharer.save({ filename: 'backup.zip', contentType: 'application/zip', base64Data: zipBase64, android: { saveDirectory: 'downloads', relativePath: 'Download/My App', },});
console.log(result.uri);Androidの保存ディレクトリは downloads, pictures, movies, music, そして documents。Android 10 以降では、プラグインは MediaStore を介して書き込まれます。Android 9 以下では、パブリック セーブはマニフェスト WRITE_EXTERNAL_STORAGE 許可権と maxSdkVersion=28.
ファイルとテキストを共有
セクション「ファイルとテキストを共有」await FileSharer.share({ filename: 'photo.jpg', contentType: 'image/jpeg', path: photoUri, title: 'Site photo', subject: 'Photo export', text: 'Captured during inspection.',});text は Android で EXTRA_TEXT iOS で 2 番目のアクティビティ アイテムとして渡されます。
種類の参照
「種類の参照」ShareFileOptions
「ShareFileOptions」export interface ShareFileOptions { filename: string; base64Data?: string; path?: string; contentType?: string; text?: string; title?: string; subject?: string; android?: AndroidFileSharerOptions;}AndroidFileSharerOptions
「AndroidFileSharerOptions」export interface AndroidFileSharerOptions { chooserTitle?: string; saveDirectory?: 'downloads' | 'pictures' | 'movies' | 'music' | 'documents'; relativePath?: string;}SaveFileResult
「SaveFileResult」export interface SaveFileResult { uri?: string;}エラーコード
「エラーコード」ERR_PARAM_NO_FILENAME-filename値が存在しないERR_PARAM_NO_DATA- どちらもbase64Dataないpath提供されていませんでした。ERR_PARAM_DATA_INVALID- base64 入力がデコードできませんでした。ERR_LOCAL_FILE_NOT_FOUND- 提供されたローカルパスまたはコンテンツURIが開けませんでした。ERR_FILE_CACHING_FAILED- ネイティブのトemporaryファイルが書き込めませんでした。ERR_FILE_SAVE_FAILED- Androidがパブリックストレージにファイルを保存できませんでした。ERR_ACTIVITY_NOT_FOUND- Androidが共有ターゲットを開くことができませんでした。USER_CANCELLED- iOSの共有シートが完了せずに閉じられました。
真実の源
「真実の源」というセクションこのページはプラグインの src/definitions.ts。 公開された API がアップストリームで変更された場合、再度同期を実行してください。
続けて始めましょう
「続けて始めましょう」あなたが使用している Getting Started データの保存とファイルの管理を計画するために使用している場合 Using @capgo/capacitor-file-sharer Capacitorのネイティブ機能としてのUsing @capgo/capacitor-file-sharer @capgo/capacitor-data-storage-sqlite @capgo/capacitor-data-storage-sqliteの実装詳細 Using @capgo/capacitor-data-storage-sqlite Capacitorのネイティブ機能としてのUsing @capgo/capacitor-data-storage-sqlite @capgo/capacitor-file for the implementation detail in @capgo/capacitor-file, and Using @capgo/capacitor-file for the native capability in Using @capgo/capacitor-file.