@byteowls/capacitor-filesharer

中文文档
7.0.0发布于 2025/07/23MITTypeScriptESM + CJS近 30 天下载 1.6万

Capacitor plugin to download and share files for the Web, Android and iOS

原始使用文档
文档目录11 节
  1. File Sharing
  2. Introduction
  3. Installation
  4. Versions
  5. Configuration
  6. Error Codes
  7. Platform: Android
  8. Contribute
  9. Changelog
  10. License
  11. Disclaimer


File Sharing

@byteowls/capacitor-filesharer

Capacitor File Sharing plugin


Introduction

Capacitor plugin to share files on Android and iOS using the native share dialog and on Web using the FileSaver lib.

Installation

npm i @byteowls/capacitor-filesharer
npx cap sync

For further details on what has changed see the CHANGELOG.

Versions

PluginFor CapacitorDocsNotes
7.x7.x.xREADMEBreaking changes see Changelog.
6.x6.x.xREADMEBreaking changes see Changelog.

Configuration

import {
  FileSharer
} from '@byteowls/capacitor-filesharer';

@Component({
  template: '<button (click)="downloadButtonClick()">Download file</button>'
})
export class SignupComponent {
    downloadButtonClick() {
        FileSharer.share({
            filename: "test.pdf",
            contentType: "application/pdf",
            // If you want to save base64:
            base64Data: "...",
            // If you want to save a file from a path:
            path: "../../file.pdf",
        }).then(() => {
            // do sth
        }).catch(error => {
            console.error("File sharing failed", error.message);
        });
    }
}

Error Codes

  • ERR_PARAM_NO_FILENAME ... Filename missing or invalid.
  • ERR_PARAM_NO_DATA ... Base64 data missing.
  • ERR_PARAM_NO_CONTENT_TYPE ... Content type missing
  • ERR_PARAM_DATA_INVALID ... Base64 data is invalid. See this comment for a possible error.
  • ERR_FILE_CACHING_FAILED ... Caching the file in temp directory on the device failed.

Platform: Android

Add outState.clear() to your MainActivity. This fixes android.os.TransactionTooLargeException when sharing larger files.

package com.company.project;

import android.os.Bundle;
import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {

  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.clear();
  }
}

Contribute

See Contribution Guidelines.

Changelog

See CHANGELOG.

License

MIT

Disclaimer

We have no business relation to Ionic.

版本与发布记录

@byteowls/capacitor-filesharer 共发布 14 个版本,首次发布于 2018/12/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
7.0.0latest2025/07/231.3 年前
6.0.02024/07/262 年前
5.0.02023/09/043 年前
4.0.02022/09/194 年前
3.0.02021/09/235 年前
2.0.02020/04/106 年前

关于 @byteowls/capacitor-filesharer 的常见问题

@byteowls/capacitor-filesharer 是什么?

Capacitor plugin to download and share files for the Web, Android and iOS

如何安装 @byteowls/capacitor-filesharer?

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

@byteowls/capacitor-filesharer 支持 TypeScript 吗?

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

@byteowls/capacitor-filesharer 支持 ESM 还是 CommonJS?

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

@byteowls/capacitor-filesharer 可以商用吗?

@byteowls/capacitor-filesharer 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@byteowls/capacitor-filesharer 的下载量有多少?

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

@byteowls/capacitor-filesharer 还在维护吗?

最新版本 7.0.0 发布于 2025/07/23(1.3 年前);至今共发布 14 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/12/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。