Skip to content

Getting Started

Terminal window
bun add @capgo/capacitor-file-sharer
bunx cap sync
import { FileSharer } from '@capgo/capacitor-file-sharer';
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,....

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.

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.

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.

export interface ShareFileOptions {
filename: string;
base64Data?: string;
path?: string;
contentType?: string;
text?: string;
title?: string;
subject?: string;
android?: AndroidFileSharerOptions;
}
export interface AndroidFileSharerOptions {
chooserTitle?: string;
saveDirectory?: 'downloads' | 'pictures' | 'movies' | 'music' | 'documents';
relativePath?: string;
}
export interface SaveFileResult {
uri?: string;
}
  • ERR_PARAM_NO_FILENAME - filename is missing or blank.
  • ERR_PARAM_NO_DATA - neither base64Data nor path was 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.

This page tracks the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.