Giter VIP home page Giter VIP logo

cordova-plugin-chooser's Introduction

Chooser

Overview

File chooser plugin for Cordova.

Install with Cordova CLI:

$ cordova plugin add cordova-plugin-chooser

Supported Platforms:

  • Android

  • iOS

API

/**
 * Displays native prompt for user to select a file.
 *
 * @param accept Optional MIME type filter (e.g. 'image/gif,video/*').
 *
 * @returns Promise containing selected file's raw binary data,
 * base64-encoded data: URI, MIME type, display name, and original URI.
 *
 * If user cancels, promise will be resolved as undefined.
 * If error occurs, promise will be rejected.
 */
chooser.getFile(accept?: string) : Promise<undefined|{
	data: Uint8Array;
	dataURI: string;
	mediaType: string;
	name: string;
	uri: string;
}>

/**
 * Displays native prompt for user to select a file.
 *
 * @param accept Optional MIME type filter (e.g. 'image/gif,video/*').
 *
 * @returns Promise containing selected file's MIME type, display name,
 * and original URI.
 *
 * If user cancels, promise will be resolved as undefined.
 * If error occurs, promise will be rejected.
 */
chooser.getFileMetadata(accept?: string) : Promise<undefined|{
	mediaType: string;
	name: string;
	uri: string;
}>

Example Usage

(async () => {
	const file = await chooser.getFile();
	console.log(file ? file.name : 'canceled');
})();

Platform-Specific Notes

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>

If it isn't present already, you'll also need the attribute xmlns:android="http://schemas.android.com/apk/res/android" added to your <widget> tag in order for that to build successfully.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.