@capgo/capacitor-file-sharer

中文文档
8.1.16发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.6万

Capacitor plugin for sharing and saving files on Android, iOS, and Web.

原始使用文档
文档目录18 节
  1. ➡️ Get started for free
  2. Key features
  3. Compatibility
  4. Install
  5. Usage
  6. Integration Notes
  7. Android
  8. iOS
  9. Web
  10. Error Codes
  11. API
  12. share(...)
  13. save(...)
  14. getPluginVersion()
  15. Interfaces
  16. Type Aliases
  17. Contributing
  18. License

@capgo/capacitor-file-sharer

Share files through the native share sheet from your Capacitor app, or save them to the device on Android. On web, the same calls download the file.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-file-sharer in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-file-sharer to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-file-sharer for Capacitor apps

Key features

  • Share: share() opens the native share sheet on iOS and Android.
  • Save: on Android, save() stores the file with MediaStore where supported and a legacy path on older versions. On iOS it opens the share sheet so the user picks the destination.
  • Flexible input: pass base64 data or a local file.
  • Web fallback: both methods download the file in the browser.
  • Platforms: iOS, Android and Web.

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8..v8..Yes
v7..v7..On demand
v6..v6..On demand

The plugin major version follows the Capacitor major version. New work targets Capacitor 8 first.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-file-sharer` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

bun add @capgo/capacitor-file-sharer
bunx cap sync

Usage

import { FileSharer } from '@capgo/capacitor-file-sharer';

await FileSharer.share({
  filename: 'report.pdf',
  contentType: 'application/pdf',
  base64Data: reportBase64,
  title: 'Quarterly report',
  text: 'Attached report',
});

Share from a local file path or Capacitor file URL:

await FileSharer.share({
  filename: 'movie.mp4',
  contentType: 'video/mp4',
  path: fileUri,
});

Save directly on Android or download on Web:

const result = await FileSharer.save({
  filename: 'backup.zip',
  contentType: 'application/zip',
  base64Data: zipBase64,
  android: {
    saveDirectory: 'downloads',
    relativePath: 'Download/My App',
  },
});

console.log(result.uri);

Integration Notes

Android

  • Sharing uses a FileProvider, ClipData, and URI grants so Android's chooser can read previews and thumbnails.
  • share() resolves after the Android chooser opens. This avoids retaining large base64 payloads in activity state.
  • save() writes to MediaStore on Android 10+ and to the matching public directory on older Android versions.
  • Android 9 and below require WRITE_EXTERNAL_STORAGE for public saves; the plugin manifest includes it with maxSdkVersion=28.
  • Android save directories: downloads, pictures, movies, music, and documents.

iOS

  • share() supports base64Data and direct local path sharing.
  • save() opens the native share sheet so the user can choose Save to Files or another destination.
  • Swift Package Manager and CocoaPods are both supported.

Web

  • share() and save() download the file in the browser.
  • Base64 conversion is chunked to avoid large-array allocation failures in Chromium.

Error Codes

  • 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: iOS share sheet was dismissed without completing.

API

Capacitor File Sharer plugin.

share(...)

share(options: ShareFileOptions) => Promise<void>

Share a file using the native share sheet on Android and iOS. On web, this downloads the file because browsers do not expose a consistent native file share target.

ParamType
optionsShareFileOptions

save(...)

save(options: SaveFileOptions) => Promise<SaveFileResult>

Save a file locally. On Android this writes to MediaStore/Downloads. On web this downloads the file. On iOS this opens the share sheet so the user can choose Save to Files or another target.

ParamType
optionsShareFileOptions

Returns: Promise<SaveFileResult>


getPluginVersion()

getPluginVersion() => Promise<PluginVersionResult>

Returns the platform implementation version marker.

Returns: Promise<PluginVersionResult>


Interfaces

ShareFileOptions

Options used to share a file.

PropTypeDescription
filenamestringFile name presented to the receiving app. Include the extension.
base64DatastringBase64 encoded file data. Data URL prefixes are accepted.
pathstringLocal file path, file:// URL, content:// URL, or Capacitor capacitor_file URL.
contentTypestringMIME type of the file. Defaults to application/octet-stream when omitted.
textstringOptional text or caption shared with the file.
titlestringOptional title for the share sheet or shared item.
subjectstringOptional subject used by mail and compatible share targets.
androidAndroidFileSharerOptionsAndroid-specific options.

AndroidFileSharerOptions

Android-specific behavior for file sharing and saving.

PropTypeDescription
chooserTitlestringTitle shown at the top of the Android chooser.
saveDirectoryAndroidSaveDirectoryPublic collection used by save(). Defaults from contentType.
relativePathstringOptional relative folder inside the selected public collection on Android 10+.

SaveFileResult

Result returned by save().

PropTypeDescription
uristringNative URI of the saved file when the platform provides one.

PluginVersionResult

Plugin version payload.

PropTypeDescription
versionstringVersion identifier returned by the platform implementation.

Type Aliases

AndroidSaveDirectory

Android public collection used by save().

'downloads' | 'pictures' | 'movies' | 'music' | 'documents'

SaveFileOptions

Options used to save a file locally.

ShareFileOptions

Contributing

See CONTRIBUTING.md.

License

MPL-2.0

版本与发布记录

@capgo/capacitor-file-sharer 共发布 17 个版本,首次发布于 2026/05/06;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.16latest2026/10/1525 天前
8.1.152026/10/1327 天前
8.1.142026/10/091 个月前
8.1.132026/10/091 个月前
8.1.112026/10/081 个月前
8.1.122026/10/081 个月前

关于 @capgo/capacitor-file-sharer 的常见问题

@capgo/capacitor-file-sharer 是什么?

Capacitor plugin for sharing and saving files on Android, iOS, and Web.

如何安装 @capgo/capacitor-file-sharer?

在项目目录运行 npm install @capgo/capacitor-file-sharer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-file-sharer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-file-sharer 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-file-sharer 可以商用吗?

@capgo/capacitor-file-sharer 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-file-sharer 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-file-sharer 在 2026/10/09 – 2026/11/07 这 30 天内被下载 45,652 次,日均约 1,522 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-file-sharer 还在维护吗?

最新版本 8.1.16 发布于 2026/10/15(25 天前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/05/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。