Socket
Socket
Sign inDemoInstall

@capacitor-community/file-opener

Package Overview
Dependencies
2
Maintainers
43
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @capacitor-community/file-opener

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


Version published
Weekly downloads
26K
increased by1.98%
Maintainers
43
Created
Weekly downloads
 

Changelog

Source

v6.0.0 (2024-04-22)

Chores

  • support capacitor v6.0.0 (#55), (9427ffc), closes #54

Readme

Source


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
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);
}

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 13 or higher (for more details please see)

platform :ios '13.0'

then npx cap sync ios

Keywords

FAQs

Last updated on 22 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc