Socket
Socket
Sign inDemoInstall

@pragli/react-native-image-picker

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @pragli/react-native-image-picker

A React Native module that allows you to use native UI to select media from the device library or directly from the camera


Version published
Maintainers
1
Created

Readme

Source

React Native Image Picker

A React Native module that allows you to select a photo/video from the device library or camera.

Note: If you are still using deprecated version 2.x.x check this for documentation.

Migration from 2.x.x to 3.x.x

  • showImagePicker API is removed.
  • No permission required for default options on Android.
  • Removed and updated some values in options, so please check them carefully.

Install

yarn add react-native-image-picker

# RN >= 0.60
cd ios && pod install

# RN < 0.60
react-native link react-native-image-picker

Post-install Steps

iOS

Add the appropriate keys to your Info.plist,

If you are allowing user to select image/video from photos, add NSPhotoLibraryUsageDescription.

If you are allowing user to capture image add NSCameraUsageDescription key also.

If you are allowing user to capture video add NSCameraUsageDescription add NSMicrophoneUsageDescription key also.

Android

No permissions required (saveToPhotos requires permission check).

Note: This library does not require Manifest.permission.CAMERA, if your app declares as using this permission in manifest then you have to obtain the permission before using launchCamera.

API Reference

Methods

import {launchCamera, launchImageLibrary} from 'react-native-image-picker';

launchCamera()

Launch camera to take photo or video.

launchCamera(options?, callback);

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

launchImageLibrary

Launch gallery to pick image or video.

launchImageLibrary(options?, callback)

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

Options

OptioniOSAndroidDescription
mediaTypeOKOK'photo' or 'video' or 'mixed'(mixed supported only for launchImageLibrary, to pick an photo or video)
maxWidthOKOKTo resize the image
maxHeightOKOKTo resize the image
videoQualityOKOK'low', 'medium', or 'high' on iOS, 'low' or 'high' on Android
durationLimitOKOKVideo max duration in seconds
qualityOKOK0 to 1, photos
cameraTypeOKOK'back' or 'front'. May not be supported in few android devices
includeBase64OKOKIf true, creates base64 string of the image (Avoid using on large image files due to performance)
saveToPhotosOKOK(Boolean) Only for launchCamera, saves the image/video file captured to public photo

The Response Object

keyiOSAndroidDescription
didCancelOKOKtrue if the user cancelled the process
errorCodeOKOKCheck ErrorCode for all error codes
errorMessageOKOKDescription of the error, use it for debug purpose only
base64OKOKThe base64 string of the image (photos only)
uriOKOKThe file uri in app specific cache storage. Except when picking video from Android gallery where you will get read only content uri, to get file uri in this case copy the file to app specific storage using any react-native library
widthOKOKImage dimensions (photos only)
heightOKOKImage dimensions (photos only)
fileSizeOKOKThe file size (photos only)
typeOKOKThe file type (photos only)
fileNameOKOKThe file name
durationOKOKThe selected video duration in seconds

Note on file storage

Image/video captured via camera will be stored in temporary folder so will be deleted any time, so don't expect it to persist. Use saveToPhotos: true (default is false) to save the file in the public photos. saveToPhotos requires WRITE_EXTERNAL_STORAGE permission on Android 28 and below (You have to obtain the permission, the library does not).

ErrorCode

CodeDescription
camera_unavailablecamera not available on device
permissionPermission not satisfied
othersother errors (check errorMessage for description)

License

MIT

Keywords

FAQs

Last updated on 24 May 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc