-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* <platform name="android"> | ||
* <edit-config | ||
* file="app/src/main/AndroidManifest.xml" | ||
* mode="merge" | ||
* target="/manifest/application"> | ||
* <application android:largeHeap="true" /> | ||
* </edit-config> | ||
* </platform> | ||
* ``` | ||
* | ||
* @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<any>} Promise containing selected file's raw binary data, | ||
* base64-encoded data: URI, MIME type, display name, and original URI. | ||
*/ | ||
@Cordova() | ||
getFile(accept: string): Promise<ChooserResult | undefined> { | ||
return; | ||
} | ||
} |