Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@capacitor/file-viewer

Package Overview
Dependencies
Maintainers
17
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor/file-viewer

The FileViewer API provides mechanisms for opening files and previewing media. Not available on web.

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
2.6K
-30%
Maintainers
17
Weekly downloads
 
Created
Source

@capacitor/file-viewer

The FileViewer API provides mechanisms for opening files and previewing media. Not available on web.

The media preview methods are currently only supported on iOS. It uses a built-in player.

Install

npm install @capacitor/file-viewer
npx cap sync

Example

import { FileViewer } from "@capacitor/file-viewer";

// can use a plugin like @capacitor/filesystem to get the full path to the file
const openDocument = async () => {
  await FileViewer.openDocumentFromLocalPath({
    path: "path/to/file.pdf"
  });
};

// ios-specific
const previewMedia = async () => {
  await FileViewer.previewMediaContentFromUrl({
    path: "https://url_hosting_media/file.mp4"
  });
}

API

  • openDocumentFromLocalPath(...)
  • openDocumentFromResources(...)
  • openDocumentFromUrl(...)
  • previewMediaContentFromLocalPath(...)
  • previewMediaContentFromResources(...)
  • previewMediaContentFromUrl(...)
  • Interfaces
  • Type Aliases

For list of existing error codes, see Errors.

File Viewer API

Only available in Native Android and iOS; not available for Web / PWAs.

openDocumentFromLocalPath(...)

openDocumentFromLocalPath(options: OpenFromLocalPathOptions) => Promise<void>

Open a file stored in the local file system

ParamType
optionsOpenFromLocalPathOptions

Since: 1.0.0

openDocumentFromResources(...)

openDocumentFromResources(options: OpenFromResourcesOptions) => Promise<void>

Open an app resource file

ParamType
optionsOpenFromResourcesOptions

Since: 1.0.0

openDocumentFromUrl(...)

openDocumentFromUrl(options: OpenFromUrlOptions) => Promise<void>

Open a file from a remote url

ParamType
optionsOpenFromUrlOptions

Since: 1.0.0

previewMediaContentFromLocalPath(...)

previewMediaContentFromLocalPath(options: PreviewMediaFromLocalPathOptions) => Promise<void>

Preview a media file (namely, video) stored in the local file system. Only implemented in iOS. Android defaults to openDocumentFromLocalPath.

ParamType
optionsOpenFromLocalPathOptions

Since: 1.0.0

previewMediaContentFromResources(...)

previewMediaContentFromResources(options: PreviewMediaFromResourcesOptions) => Promise<void>

Preview a media file (namely, video) from the app's resources. Only implemented in iOS. Android defaults to openDocumentFromResources.

ParamType
optionsOpenFromResourcesOptions

Since: 1.0.0

previewMediaContentFromUrl(...)

previewMediaContentFromUrl(options: PreviewMediaFromUrlOptions) => Promise<void>

Preview a media file (namely, video) from a remote url. Only implemented in iOS. Android defaults to openDocumentFromUrl.

ParamType
optionsOpenFromUrlOptions

Since: 1.0.0

Interfaces

OpenFromLocalPathOptions

PropTypeDescriptionSince
pathstringThe full absolute path to the file to open1.0.0

OpenFromResourcesOptions

PropTypeDescriptionSince
pathstringThe relative path to the resource file to open1.0.0

OpenFromUrlOptions

PropTypeDescriptionSince
urlstringThe remote url pointing to the file to open1.0.0

Type Aliases

PreviewMediaFromLocalPathOptions

OpenFromLocalPathOptions

PreviewMediaFromResourcesOptions

OpenFromResourcesOptions

PreviewMediaFromUrlOptions

OpenFromUrlOptions

Errors

The plugin returns the following errors with specific codes on native Android and iOS:

Error codePlatform(s)Message
OS-PLUG-FLVW-0004Android, iOSThe file you are trying to open does not exist.
OS-PLUG-FLVW-0005Android, iOSThe URL you are trying to open is malformed.
OS-PLUG-FLVW-0006Android, iOSPath of the file to open is either null or empty.
OS-PLUG-FLVW-0007Android, iOSURL to open is either null or empty.
OS-PLUG-FLVW-0008Android, iOSCould not open the file.
OS-PLUG-FLVW-0009Android, iOSInvalid parameters.
OS-PLUG-FLVW-0010AndroidThere is no app to open this file.
OS-PLUG-FLVW-0011iOSCordova / Capacitor bridge isn’t initialized.
OS-PLUG-FLVW-0012iOSThe download failed.
OS-PLUG-FLVW-0013iOSThe file has no extension.

Keywords

capacitor

FAQs

Package last updated on 08 Oct 2025

Did you know?

Socket

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