0.3.0-dev.d8fa252.1657736483 • Published 4 years ago

@robingenz/capacitor-file-picker v0.3.0-dev.d8fa252.1657736483

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

Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

npm install @robingenz/capacitor-file-picker
npx cap sync

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

import { FilePicker } from '@robingenz/capacitor-file-picker';

const pickFiles = async () => {
  const result = await FilePicker.pickFiles({
    types: ['image/png'],
    multiple: true,
  });
};

const appendFileToFormData = async () => {
  const result = await FilePicker.pickFiles();
  const file = result.files[0];

  const formData = new FormData();
  if (file.blob) {
    const rawFile = new File(file.blob, file.name, {
      type: file.mimeType,
    });
    formData.append('file', rawFile, file.name);
  }
};

API

pickFiles(...)

pickFiles(options?: PickFilesOptions | undefined) => Promise<PickFilesResult>

Open the file picker that allows the user to select one or more files.

ParamType
optionsPickFilesOptions

Returns: Promise<PickFilesResult>


Interfaces

PickFilesResult

PropType
filesFile[]

File

PropTypeDescription
pathstringThe path of the file. Only available on Android and iOS.
namestringThe name of the file.
datastringThe Base64 string representation of the data contained in the file. Is only provided if readData is set to true.
mimeTypestringThe mime type of the file.
sizenumberThe size of the file in bytes.
blobBlobThe Blob instance of the file. Only available on Web.

PickFilesOptions

PropTypeDescription
typesstring[]List of accepted file types. Look at IANA Media Types for a complete list of standard media types. This option cannot be used with multiple: true on Android. Example: ['image/png', 'application/pdf']
multiplebooleanWhether multiple files may be selected. Default: false
readDatabooleanWhether to read the file data. Default: true

Changelog

See CHANGELOG.md.

License

See LICENSE.