New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@capawesome/capacitor-file-picker

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capawesome/capacitor-file-picker

Capacitor plugin that allows the user to select a file.

  • 7.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24K
increased by7.77%
Maintainers
1
Weekly downloads
 
Created
Source

@capawesome/capacitor-file-picker

Capacitor plugin that allows the user to select a file.

Installation

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

Android

Permissions

This API requires the following permissions be added to your AndroidManifest.xml before or after the application tag:

<!-- Needed if you want to retrieve unredacted EXIF metadata from photos -->
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
<!-- Needed if you want to read files from external storage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

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 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);
  }
};

const checkPermissions = async () => {
  const result = await FilePicker.checkPermissions();
};

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

const pickDirectory = async () => {
  const result = await FilePicker.pickDirectory();
};

const pickImages = async () => {
  const result = await FilePicker.pickImages();
};

const pickMedia = async () => {
  const result = await FilePicker.pickMedia();
};

const pickVideos = async () => {
  const result = await FilePicker.pickVideos();
};

const requestPermissions = async () => {
  const result = await FilePicker.requestPermissions();
};

API

checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check permissions to access files.

Only available on Android.

Returns: Promise<PermissionStatus>

Since: 6.1.0


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>


pickDirectory()

pickDirectory() => Promise<PickDirectoryResult>

Open a picker dialog that allows the user to select a directory.

Only available on Android and iOS.

Returns: Promise<PickDirectoryResult>

Since: 6.2.0


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


requestPermissions(...)

requestPermissions(options?: RequestPermissionsOptions | undefined) => Promise<PermissionStatus>

Request permissions to access files.

Only available on Android.

ParamType
optionsRequestPermissionsOptions

Returns: Promise<PermissionStatus>

Since: 6.1.0


addListener('pickerDismissed', ...)

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

Called when the file picker is dismissed.

Only available on iOS.

ParamType
eventName'pickerDismissed'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 0.6.2


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.6.2


Interfaces

PermissionStatus
PropTypeDescriptionSince
accessMediaLocationPermissionStatePermission state for accessing media location. On Android, this requests/checks the ACCESS_MEDIA_LOCATION permission.6.1.0
readExternalStoragePermissionStatePermission state for reading external storage. On Android, this requests/checks the READ_EXTERNAL_STORAGE permission.6.1.0
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
filesPickedFile[]
PickedFile
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
PropTypeDescriptionDefaultSince
typesstring[]List of accepted file types. Look at IANA Media Types for a complete list of standard media types. This option is ignored if limit is set.
limitnumberThe maximum number of files that the user can select. Setting this to 0 sets the selection limit to unlimited. Currently, only 0 and 1 are supported.06.0.0
readDatabooleanWhether to read the file data.false
PickDirectoryResult
PropTypeDescriptionSince
pathstringThe path to the selected directory.6.2.0
PickMediaOptions
PropTypeDescriptionDefaultSince
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.true
limitnumberThe maximum number of files that the user can select. Setting this to 0 sets the selection limit to unlimited. On Android and Web, only 0 and 1 are supported.05.2.0
orderedbooleanWhether an ordered number is displayed instead of a check mark in the selection badge. Only available on iOS (15+).false5.3.0
RequestPermissionsOptions
PropTypeDescriptionDefaultSince
permissionsPermissionType[]The permissions to request.["accessMediaLocation", "readExternalStorage"]6.1.0
PluginListenerHandle
PropType
remove() => Promise<void>

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

PickImagesOptions

PickMediaOptions

PickImagesResult

PickMediaResult

PickMediaResult

PickFilesResult

PickVideosOptions

PickMediaOptions

PickVideosResult

PickMediaResult

PermissionType

'accessMediaLocation' | 'readExternalStorage'

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!

Keywords

FAQs

Package last updated on 01 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc