Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/capacitor-community/file-opener
Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.
https://github.com/capacitor-community/file-opener
Last synced: 3 months ago
JSON representation
Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.
- Host: GitHub
- URL: https://github.com/capacitor-community/file-opener
- Owner: capacitor-community
- License: mit
- Created: 2022-08-17T11:50:58.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-02T05:56:10.000Z (6 months ago)
- Last Synced: 2024-07-19T14:59:17.678Z (4 months ago)
- Language: Swift
- Size: 311 KB
- Stars: 62
- Watchers: 8
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-capacitor - File opener - The plugin is able to open a file given the mimeType and the file uri. (Community plugins)
README
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](#maintainers)
- [About](#about)
- [Plugin versions](#plugin-versions)
- [Installation](#installation)
- [API](#api)## Maintainers
| Maintainer | GitHub | Active |
| ---------- | ------------------------------- | ------ |
| ryaa | [ryaa](https://github.com/ryaa) | yes |## About
This plugin is similar to cordova-plugin-file-opener2 but without installation support.
## Plugin versions
| Capacitor version | Plugin version |
| ----------------- | -------------- |
| 6.x | 6.x |
| 5.x | 1.0.5 |
| 4.x | 1.0.4 |## Installation
```bash
npm install @capacitor-community/file-opener
npx cap sync
```## Usage
```typescript
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);
}
```## API
* [`open(...)`](#open)
* [Interfaces](#interfaces)### open(...)
```typescript
open(options: FileOpenerOptions) => Promise
```Method to open a file.
| Param | Type |
| ------------- | --------------------------------------------------------------- |
| **`options`** |FileOpenerOptions
|**Since:** 1.0.0
--------------------
### Interfaces
#### FileOpenerOptions
file open method options
| Prop | Type | Description | Since |
| --------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`filePath`** |string
| file path | 1.0.0 |
| **`contentType`** |string
| MIME type (optional) | 1.0.0 |
| **`openWithDefault`** |boolean
| Use 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 true | 1.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 ignored | 1.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.
| Code | Description |
| ----: | :------------------- |
| '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:
```diff
+
```
### iOS
You'll need to set ios/App/Podfile to version 13 or higher (for more details please [see](https://capacitorjs.com/docs/ios#ios-support))
```
platform :ios '13.0'
```then `npx cap sync ios`