はじめに
このプラグインのインストール手順とフルマークダウンガイドを含むセットアップの質問をコピーします。
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-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-sharer` plugin in my project.Manual Setupを使用する場合は、以下のコマンドを実行してください。プラットフォーム固有の指示に従ってください。
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、__CAPGO_KEEP_0__、URLをサポートしています file:// Share A Local File content:// URIs, and Capacitor _capacitor_file_ Copy to clipboard
ファイルを保存
「ファイルを保存」のセクション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- ネイティブのテンポラリファイルが書き込めませんでした。ERR_FILE_SAVE_FAILED- Androidがパブリックストレージにファイルを保存できませんでした。ERR_ACTIVITY_NOT_FOUND- Androidが共有ターゲットを開くことができませんでした。USER_CANCELLED- iOSの共有シートが完了せずに閉じられました。
真実の源
「真実の源」というセクションこのページはプラグインの src/definitions.tsを追跡します。再度、パブリックAPIがアップストリームで変更された場合、パブリックAPIを再度同步してください。
続けて始めましょう
「続けて始めましょう」あなたが使用している 「Getting Started」 データの保存とファイルの管理を計画するために使用している場合 「@capgo/capacitor-file-sharer」 「@capgo/capacitor-file-sharer」 「@capgo/capacitor-data-storage-sqlite」 「@capgo/capacitor-data-storage-sqlite」 「@capgo/capacitor-data-storage-sqlite」 「@capgo/capacitor-file」 「@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.