Getting Started
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
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.
Install
Section titled “Install”bun add @capgo/capacitor-file-sharerbunx cap syncImport
Section titled “Import”import { FileSharer } from '@capgo/capacitor-file-sharer';Share A Base64 File
Section titled “Share A Base64 File”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 can be a raw base64 string or a data URL such as data:application/pdf;base64,....
Share A Local File
Section titled “Share A Local File”await FileSharer.share({ filename: 'export.zip', contentType: 'application/zip', path: fileUri,});The native implementations accept local paths, file:// URLs, Android content:// URIs, and Capacitor _capacitor_file_ URLs.
Save A File
Section titled “Save A File”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 save directories are downloads, pictures, movies, music, and documents. On Android 10 and newer, the plugin writes through MediaStore. On Android 9 and below, public saves use the manifest WRITE_EXTERNAL_STORAGE permission with maxSdkVersion=28.
Share Text With A File
Section titled “Share Text With A File”await FileSharer.share({ filename: 'photo.jpg', contentType: 'image/jpeg', path: photoUri, title: 'Site photo', subject: 'Photo export', text: 'Captured during inspection.',});text is passed as EXTRA_TEXT on Android and as a second activity item on iOS.
Type Reference
Section titled “Type Reference”ShareFileOptions
Section titled “ShareFileOptions”export interface ShareFileOptions { filename: string; base64Data?: string; path?: string; contentType?: string; text?: string; title?: string; subject?: string; android?: AndroidFileSharerOptions;}AndroidFileSharerOptions
Section titled “AndroidFileSharerOptions”export interface AndroidFileSharerOptions { chooserTitle?: string; saveDirectory?: 'downloads' | 'pictures' | 'movies' | 'music' | 'documents'; relativePath?: string;}SaveFileResult
Section titled “SaveFileResult”export interface SaveFileResult { uri?: string;}Error Codes
Section titled “Error Codes”ERR_PARAM_NO_FILENAME-filenameis missing or blank.ERR_PARAM_NO_DATA- neitherbase64Datanorpathwas provided.ERR_PARAM_DATA_INVALID- base64 input could not be decoded.ERR_LOCAL_FILE_NOT_FOUND- the provided local path or content URI could not be opened.ERR_FILE_CACHING_FAILED- the native temporary file could not be written.ERR_FILE_SAVE_FAILED- Android could not save the file to public storage.ERR_ACTIVITY_NOT_FOUND- Android could not open a share target.USER_CANCELLED- the iOS share sheet was dismissed without completing.
Source Of Truth
Section titled “Source Of Truth”This page tracks the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.