Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.1k
🌄 A React Native module that allows you to use native UI to select media from the device library or directly from the camera.
License
react-native-image-picker/react-native-image-picker
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A React Native module that allows you to select a photo/video from the device library or camera.
yarn add react-native-image-picker
To take advantage of the new architecture run-
RCT_NEW_ARCH_ENABLED=1 npx pod-install ios
SetnewArchEnabled totrue insideandroid/gradle.properties
npx pod-install ios
Add the appropriate keys to yourInfo.plist depending on your requirement:
| Requirement | Key |
|---|---|
| Select image/video from photos | NSPhotoLibraryUsageDescription |
| Capture Image | NSCameraUsageDescription |
| Capture Video | NSCameraUsageDescription & NSMicrophoneUsageDescription |
No permissions required (saveToPhotos requires permissioncheck).
Note: This library does not requireManifest.permission.CAMERA, if your app declares as using this permission in manifest then you have to obtain the permission before usinglaunchCamera.
If your app'sminSdkVersion is set to below 30 and it does not already include or depend onandroidx.activity:activity:1.9.+ or a newer version, you'll need to add the following line to the dependencies section of yourapp/build.gradle file to ensure support for the backported AndroidX Photo Picker:
dependencies {... implementation("androidx.activity:activity:1.9.+")...}Additionally, you may need to update yourAndroidManifest.xml to trigger the installation of the backported Photo Picker. For reference, you can check the example app's configuration inexample/android/app/src/main/AndroidManifest.xml andexample/android/app/build.gradle.
For more details, consult the Android documentation on AndroidX Photo Picker:https://developer.android.com/training/data-storage/shared/photopicker
import{launchCamera,launchImageLibrary}from'react-native-image-picker';
Launch camera to take photo or video.
launchCamera(options?,callback);// You can also use as a promise without 'callback':constresult=awaitlaunchCamera(options?);
SeeOptions for further information onoptions.
Thecallback will be called with a response object, refer toThe Response Object.
Launch gallery to pick image or video.
launchImageLibrary(options?,callback)// You can also use as a promise without 'callback':constresult=awaitlaunchImageLibrary(options?);
SeeOptions for further information onoptions.
Thecallback will be called with a response object, refer toThe Response Object.
| Option | iOS | Android | Web | Description |
|---|---|---|---|---|
| mediaType | OK | OK | OK | photo orvideo ormixed(launchCamera on Android does not support 'mixed'). Web only supports 'photo' for now. |
| restrictMimeTypes | NO | OK | NO | Array containing the mime-types allowed to be picked. Default is empty (everything). |
| maxWidth | OK | OK | NO | To resize the image. |
| maxHeight | OK | OK | NO | To resize the image. |
| videoQuality | OK | OK | NO | low,medium, orhigh on iOS,low orhigh on Android. |
| durationLimit | OK | OK | NO | Video max duration (in seconds). |
| quality | OK | OK | NO | 0 to 1, photos. |
| conversionQuality | NO | OK | NO | For conversion from HEIC/HEIF to JPEG, 0 to 1. Default is0.92 |
| cameraType | OK | OK | NO | 'back' or 'front' (May not be supported in few android devices). |
| includeBase64 | OK | OK | OK | Iftrue, creates base64 string of the image (Avoid using on large image files due to performance). |
| includeExtra | OK | OK | NO | Iftrue, will include extra data which requires library permissions to be requested (i.e. exif data). |
| saveToPhotos | OK | OK | NO | (Boolean) Only forlaunchCamera, saves the image/video file captured to public photo. |
| selectionLimit | OK | OK | OK | Supports providing any integer value. Use0 to allow any number of files on iOS version >= 14 & Android version >= 13. Default is1. |
| presentationStyle | OK | NO | NO | Controls how the picker is presented.currentContext,pageSheet,fullScreen,formSheet,popover,overFullScreen,overCurrentContext. Default iscurrentContext. |
| formatAsMp4 | OK | NO | NO | Converts the selected video to MP4 (iOS Only). |
| assetRepresentationMode | OK | OK | NO | A mode that determines which representation to use if an asset contains more than one on iOS or disables HEIC/HEIF to JPEG conversion on Android if set to 'current'. Possible values: 'auto', 'current', 'compatible'. Default is 'auto'. |
|
| key | iOS | Android | Web | Description |
|---|---|---|---|---|
| didCancel | OK | OK | OK | true if the user cancelled the process |
| errorCode | OK | OK | OK | CheckErrorCode for all error codes |
| errorMessage | OK | OK | OK | Description of the error, use it for debug purpose only |
| assets | OK | OK | OK | Array of the selected media,refer to Asset Object |
| key | iOS | Android | Web | Photo/Video | Requires Permissions | Description |
|---|---|---|---|---|---|---|
| base64 | OK | OK | OK | PHOTO ONLY | NO | The base64 string of the image (photos only) |
| uri | OK | OK | OK | BOTH | NO | The file uri in app specific cache storage. Except when pickingvideo 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. For web it uses the base64 as uri. |
| originalPath | NO | OK | NO | BOTH | NO | The original file path. |
| width | OK | OK | OK | BOTH | NO | Asset dimensions |
| height | OK | OK | OK | BOTH | NO | Asset dimensions |
| fileSize | OK | OK | NO | BOTH | NO | The file size |
| type | OK | OK | NO | BOTH | NO | The file type |
| fileName | OK | OK | NO | BOTH | NO | The file name |
| duration | OK | OK | NO | VIDEO ONLY | NO | The selected video duration in seconds |
| bitrate | --- | OK | NO | VIDEO ONLY | NO | The average bitrate (in bits/sec) of the selected video, if available. (Android only) |
| timestamp | OK | OK | NO | BOTH | YES | Timestamp of the asset. Only included if 'includeExtra' is true |
| id | OK | OK | NO | BOTH | YES | local identifier of the photo or video. On Android, this is the same as fileName |
Image/video captured via camera will be stored in temporary folder allowing it to be deleted any time, so don't expect it to persist. UsesaveToPhotos: true (default isfalse) to save the file in the public photos.saveToPhotos requiresWRITE_EXTERNAL_STORAGE permission on Android 28 and below (The permission has to obtained by the App manually as the library does not handle that).
For web, this doesn't work.
| Code | Description |
|---|---|
| camera_unavailable | Camera not available on device |
| permission | Permission not satisfied |
| others | Other errors (check errorMessage for description) |
About
🌄 A React Native module that allows you to use native UI to select media from the device library or directly from the camera.
Topics
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.