1.0.10 • Published 4 years ago

capacitor-file-picker v1.0.10

Weekly downloads
23
License
MIT
Repository
github
Last release
4 years ago

Capacitor File Picker

Description

Presents the device's native file picking ui and returns the selected file's uri.

Installation

Capacitor 2

  • npm i capacitor-file-picker@0.0.2

Capacitor 3

  • npm i capacitor-file-picker

Usage

import { Plugins } from "@capacitor/core";

const { FilePicker } = Plugins;

FilePicker.showFilePicker({
  fileTypes: ["image/*", "application/pdf"],
}).then(
  (fileResult: FilePickerResult) => {
    const fileUri = fileResult.uri;
    const fileName = fileResult.name;
    const fileMimeType = fileResult.mimeType;
    const fileExtension = fileResult.extension;
  },
  (error) => {
    console.log(error);
  }
);

Methods

MethodDefaultTypeDescription
showFilePicker(options: {fileTypes: string[]})Promise<FilePickerResult>Presents the device's native file picking ui and returns the selected file's uri.

Interfaces

FilePickerResult

PropertiesDefaultTypeDescription
uristringUri string pointing to the selected file.
namestringThe name of the selected file.
mimeTypestringThe MIME type of the selected file.
extensionstringThe extension of the selected file.

Android

Register the plugin by adding it to your MainActivity's onCreate:

import com.epicshaggy.filepicker.FilePicker;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(FilePicker.class);
    }});
  }
}

Notes

The file picker only accpets:

  • application/pdf
  • image/*

This is because it was developed to meet the need to meet a specific need, but feel free to contribute to the plugin's development. :)

1.0.9

4 years ago

1.0.8

4 years ago

1.0.10

4 years ago

1.0.2

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.2

4 years ago

0.0.1

5 years ago