Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

react-native-image-picker/react-native-image-picker

Repository files navigation

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

npm downloadsnpm packageLicense

Installation

yarn add react-native-image-picker

New Architecture

To take advantage of the new architecture run-

iOS

RCT_NEW_ARCH_ENABLED=1 npx pod-install ios

Android

SetnewArchEnabled totrue insideandroid/gradle.properties

Pre-Fabric (AKA not using the new architecture)

npx pod-install ios

Post-install Steps

iOS

Add the appropriate keys to yourInfo.plist depending on your requirement:

RequirementKey
Select image/video from photosNSPhotoLibraryUsageDescription
Capture ImageNSCameraUsageDescription
Capture VideoNSCameraUsageDescription & NSMicrophoneUsageDescription

Android

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.

Targeting Android API Levels Below 30

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

API Reference

Methods

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

launchCamera()

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.

launchImageLibrary

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.

Options

OptioniOSAndroidWebDescription
mediaTypeOKOKOKphoto orvideo ormixed(launchCamera on Android does not support 'mixed'). Web only supports 'photo' for now.
restrictMimeTypesNOOKNOArray containing the mime-types allowed to be picked. Default is empty (everything).
maxWidthOKOKNOTo resize the image.
maxHeightOKOKNOTo resize the image.
videoQualityOKOKNOlow,medium, orhigh on iOS,low orhigh on Android.
durationLimitOKOKNOVideo max duration (in seconds).
qualityOKOKNO0 to 1, photos.
conversionQualityNOOKNOFor conversion from HEIC/HEIF to JPEG, 0 to 1. Default is0.92
cameraTypeOKOKNO'back' or 'front' (May not be supported in few android devices).
includeBase64OKOKOKIftrue, creates base64 string of the image (Avoid using on large image files due to performance).
includeExtraOKOKNOIftrue, will include extra data which requires library permissions to be requested (i.e. exif data).
saveToPhotosOKOKNO(Boolean) Only forlaunchCamera, saves the image/video file captured to public photo.
selectionLimitOKOKOKSupports providing any integer value. Use0 to allow any number of files on iOS version >= 14 & Android version >= 13. Default is1.
presentationStyleOKNONOControls how the picker is presented.currentContext,pageSheet,fullScreen,formSheet,popover,overFullScreen,overCurrentContext. Default iscurrentContext.
formatAsMp4OKNONOConverts the selected video to MP4 (iOS Only).
assetRepresentationModeOKOKNOA 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'.

|

The Response Object

keyiOSAndroidWebDescription
didCancelOKOKOKtrue if the user cancelled the process
errorCodeOKOKOKCheckErrorCode for all error codes
errorMessageOKOKOKDescription of the error, use it for debug purpose only
assetsOKOKOKArray of the selected media,refer to Asset Object

Asset Object

keyiOSAndroidWebPhoto/VideoRequires PermissionsDescription
base64OKOKOKPHOTO ONLYNOThe base64 string of the image (photos only)
uriOKOKOKBOTHNOThe 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.
originalPathNOOKNOBOTHNOThe original file path.
widthOKOKOKBOTHNOAsset dimensions
heightOKOKOKBOTHNOAsset dimensions
fileSizeOKOKNOBOTHNOThe file size
typeOKOKNOBOTHNOThe file type
fileNameOKOKNOBOTHNOThe file name
durationOKOKNOVIDEO ONLYNOThe selected video duration in seconds
bitrate---OKNOVIDEO ONLYNOThe average bitrate (in bits/sec) of the selected video, if available. (Android only)
timestampOKOKNOBOTHYESTimestamp of the asset. Only included if 'includeExtra' is true
idOKOKNOBOTHYESlocal identifier of the photo or video. On Android, this is the same as fileName

Note on file storage

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.

ErrorCode

CodeDescription
camera_unavailableCamera not available on device
permissionPermission not satisfied
othersOther errors (check errorMessage for description)

License

MIT

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp