5.1.103 • Published 7 months ago

@hotend/capacitor-file-picker v5.1.103

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@hotend/capacitor-file-picker

Capacitor plugin that allows the user to select a file.

Fork Changes: Small adjustments to make ContentUris received by pickFiles persist app restarts or system reboots.

Installation

npm install @hotend/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 '@capawesome/capacitor-file-picker';

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

const pickImages = async () => {
  const result = await FilePicker.pickImages({
    multiple: true,
  });
};

const pickMedia = async () => {
  const result = await FilePicker.pickMedia({
    multiple: true,
  });
};

const pickVideos = async () => {
  const result = await FilePicker.pickVideos({
    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

convertHeicToJpeg(...)

convertHeicToJpeg(options: ConvertHeicToJpegOptions) => Promise<ConvertHeicToJpegResult>

Convert a HEIC image to JPEG.

Only available on iOS.

ParamType
optionsConvertHeicToJpegOptions

Returns: Promise<ConvertHeicToJpegResult>

Since: 0.6.0


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>


pickImages(...)

pickImages(options?: PickMediaOptions | undefined) => Promise<PickImagesResult>

Pick one or more images from the gallery.

On iOS 13 and older it only allows to pick one image.

Only available on Android and iOS.

ParamType
optionsPickMediaOptions

Returns: Promise<PickFilesResult>

Since: 0.5.3


pickMedia(...)

pickMedia(options?: PickMediaOptions | undefined) => Promise<PickMediaResult>

Pick one or more images or videos from the gallery.

On iOS 13 and older it only allows to pick one image or video.

Only available on Android and iOS.

ParamType
optionsPickMediaOptions

Returns: Promise<PickFilesResult>

Since: 0.5.3


pickVideos(...)

pickVideos(options?: PickMediaOptions | undefined) => Promise<PickVideosResult>

Pick one or more videos from the gallery.

On iOS 13 and older it only allows to pick one video.

Only available on Android and iOS.

ParamType
optionsPickMediaOptions

Returns: Promise<PickFilesResult>

Since: 0.5.3


addListener('pickerDismissed', ...)

addListener(eventName: 'pickerDismissed', listenerFunc: () => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Called when the file picker is dismissed.

Only available on iOS.

ParamType
eventName'pickerDismissed'
listenerFunc() => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 0.6.2


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.6.2


Interfaces

ConvertHeicToJpegResult

PropTypeDescriptionSince
pathstringThe path of the converted JPEG image.0.6.0

ConvertHeicToJpegOptions

PropTypeDescriptionSince
pathstringThe path of the HEIC image.0.6.0

PickFilesResult

PropType
filesFile[]

File

PropTypeDescriptionSince
blobBlobThe Blob instance of the file. Only available on Web.
datastringThe Base64 string representation of the data contained in the file. Is only provided if readData is set to true.
durationnumberThe duration of the video in seconds. Only available on Android and iOS.0.5.3
heightnumberThe height of the image or video in pixels. Only available on Android and iOS.0.5.3
mimeTypestringThe mime type of the file.
modifiedAtnumberThe last modified timestamp of the file in milliseconds.0.5.9
namestringThe name of the file.
pathstringThe path of the file. Only available on Android and iOS.
sizenumberThe size of the file in bytes.
widthnumberThe width of the image or video in pixels. Only available on Android and iOS.0.5.3

PickFilesOptions

PropTypeDescriptionDefault
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.
multiplebooleanWhether multiple files may be selected.false
readDatabooleanWhether to read the file data.false

PickMediaOptions

PropTypeDescriptionDefault
multiplebooleanWhether multiple files may be selected.false
readDatabooleanWhether to read the file data.false
skipTranscodingbooleanWhether to avoid transcoding, if possible. On iOS, for example, HEIC images are automatically transcoded to JPEG. Only available on iOS.false

PluginListenerHandle

PropType
remove() => Promise<void>

Type Aliases

PickedFile

File

PickImagesOptions

PickMediaOptions

PickImagesResult

PickMediaResult

PickMediaResult

PickFilesResult

PickVideosOptions

PickMediaOptions

PickVideosResult

PickMediaResult

Changelog

See CHANGELOG.md.

License

See LICENSE.

Credits

This plugin is based on the Capacitor File Picker plugin. Thanks to everyone who contributed to the project!

5.1.103

7 months ago

5.1.102

7 months ago

5.1.101

7 months ago

5.1.1

8 months ago