From 04db233b338936075500b4c85e050d24b80c60f5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 18 Sep 2018 15:58:57 +0200 Subject: [PATCH] feat(chooster): add plugin closes: #2612 --- src/@ionic-native/plugins/chooser/index.ts | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/@ionic-native/plugins/chooser/index.ts diff --git a/src/@ionic-native/plugins/chooser/index.ts b/src/@ionic-native/plugins/chooser/index.ts new file mode 100644 index 000000000..2b9732041 --- /dev/null +++ b/src/@ionic-native/plugins/chooser/index.ts @@ -0,0 +1,67 @@ +import { Injectable } from '@angular/core'; +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; + +export interface ChooserResult { + data: Uint8Array; + dataURI: string; + mediaType: string; + name: string; + uri: string; +} + +/** + * @name Chooser + * @description + * File chooser plugin for Cordova. + * + * The following must be added to config.xml to prevent crashing when selecting large files on Android: + * ```xml + * + * + * + * + * + * ``` + * + * @usage + * ```typescript + * 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)); + * + * ``` + * + * @interfaces + * ChooserResult + */ +@Plugin({ + pluginName: 'Chooser', + plugin: 'cordova-plugin-chooser', + pluginRef: 'chooser', + repo: 'https://github.com/cyph/cordova-plugin-chooser', + platforms: ['Android', 'iOS'] +}) +@Injectable() +export class Chooser extends IonicNativePlugin { + /** + * Displays native prompt for user to select a file. + * @param {string} [accept] Optional MIME type filter (e.g. 'image/gif,video/*'). + * @return {Promise} Promise containing selected file's raw binary data, + * base64-encoded data: URI, MIME type, display name, and original URI. + */ + @Cordova() + getFile(accept: string): Promise { + return; + } +}