Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Chooser

Improve this doc

File chooser plugin for Cordova.

The following must be added to config.xml to prevent crashing when selecting large files on Android:

<platform name="android">
 <edit-config
   file="app/src/main/AndroidManifest.xml"
   mode="merge"
   target="/manifest/application">
   <application android:largeHeap="true" />
 </edit-config>
</platform>

Repo: https://github.com/cyph/cordova-plugin-chooser

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-chooser
    $ npm install --save @ionic-native/[email protected]
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Chooser } from '@ionic-native/chooser';


constructor(private chooser: Chooser) { }

...


this.chooser.getFile()
  .then(file => console.log(file ? file.name : 'canceled'))
  .catch((error: any) => console.error(error));

Instance Members

getFile(accept)

Displays native prompt for user to select a file.

Param Type Details
accept string

Optional MIME type filter (e.g. 'image/gif,video/*').Optional

Returns: Promise<any> Promise containing selected file’s raw binary data, base64-encoded data: URI, MIME type, display name, and original URI.

ChooserResult

Param Type Details
data Uint8Array
dataURI string
mediaType string
name string
uri string

API

Native

General