@capacitor-community/file-opener

中文文档
8.0.1发布于 2026/05/29MITTypeScriptESM + CJS零依赖近 30 天下载 52.7万

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri.

原始使用文档
文档目录13 节
  1. File Opener
  2. Table of Contents
  3. Maintainers
  4. About
  5. Plugin versions
  6. Installation
  7. Usage
  8. API
  9. open(...)
  10. Interfaces
  11. List of Error Codes and Meanings
  12. Android
  13. iOS


File Opener

@capacitor-community/file-opener

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri.


Table of Contents

Maintainers

MaintainerGitHubActive
ryaaryaayes

About

This plugin is similar to cordova-plugin-file-opener2 but without installation support.

Plugin versions

Capacitor versionPlugin version
8.x8.x
7.x7.x
6.x6.x
5.x1.0.5
4.x1.0.4

Installation

npm install @capacitor-community/file-opener
npx cap sync

Usage

import { FileOpener, FileOpenerOptions } from '@capacitor-community/file-opener';

try {
  const fileOpenerOptions: FileOpenerOptions = {
    filePath: 'file:///path/to/file',
    contentType: 'application/pdf',
    openWithDefault: true,
  };
  await FileOpener.open(fileOpenerOptions);
} catch (e) {
  console.log('Error opening file', e);
}

or please see example-app for a complete example.

API

open(...)

open(options: FileOpenerOptions) => Promise<void>

Method to open a file.

ParamType
optionsFileOpenerOptions

Since: 1.0.0


Interfaces

FileOpenerOptions

file open method options

PropTypeDescriptionSince
filePathstringfile path1.0.0
contentTypestringMIME type (optional)1.0.0
openWithDefaultbooleanUse the default platform chooser, if true, otherwise: On Android: it will show "Open File in.." title of the chooser dialog, the system will always present the chooser dialog even if the user has chosen a default one and if no activity is found to handle the file, the system will still present a dialog with the specified title and an error message No application can perform this action On iOS: it will presents a menu restricted to a list of apps capable of opening the current document. This determination is made based on the document type and on the document types supported by the installed apps. To support one or more document types, an app must register those types in its Info.plist file using the CFBundleDocumentTypes key. (optional) default value is true1.0.0
chooserPosition{ x: number; y: number; }(iOS only; iPad only) Position to anchor the chooser (ShareSheet) menu in the view (optional) Please note that this is applicable only when the application runs on iPad and when openWithDefault is false, otherwise this is ignored1.0.3

List of Error Codes and Meanings

When an error is thrown, one of the following codes (as a string value) will be used.

CodeDescription
'1'INTERNAL_ERROR
'2'INVALID_ARGUMENT
' '8'FILE_NOT_SUPPORTED
'9'FILE_NOT_FOUND
'10'UNKNOWN

Android

If you app needs to open files in the external directories, then within your AndroidManifest.xml file, change the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example">

+  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

</manifest>

iOS

You'll need to set ios/App/Podfile to version 15 or higher (for more details please see)

platform :ios '15.0'

then npx cap sync ios

版本与发布记录

@capacitor-community/file-opener 共发布 13 个版本,首次发布于 2022/08/23;过去 12 个月发布了 2 个版本。

版本发布日期距今
8.0.1latest2026/05/295 个月前
8.0.02025/12/2510 个月前
7.0.12025/03/041.7 年前
7.0.02025/01/271.8 年前
6.0.12024/09/042 年前
6.0.02024/04/222 年前

关于 @capacitor-community/file-opener 的常见问题

@capacitor-community/file-opener 是什么?

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri.

如何安装 @capacitor-community/file-opener?

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

@capacitor-community/file-opener 支持 TypeScript 吗?

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

@capacitor-community/file-opener 支持 ESM 还是 CommonJS?

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

@capacitor-community/file-opener 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@capacitor-community/file-opener 可以商用吗?

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

@capacitor-community/file-opener 的下载量有多少?

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

@capacitor-community/file-opener 还在维护吗?

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