How to pick images from Camera & Gallery in React Native app (2024)

How to pick images from Camera & Gallery in React Nativeapp

How to pick images from Camera & Gallery in React Nativeapp (1)

If you would like access to the entire source code,you can check out the GitHub repo here. For step-by-step tutorial, continue reading below.

Picking images from Gallery and Camerais one of the most important and basic functionalities that is needed in almost all the apps. Advanced functionalities are built upon this basic core facility. For picking the image, we will use a popular and superior library called react-native-image-picker. Which provides the ImagePicker component in which you can provide the image picking option from Gallery or Camera.

We’ll follow a stepped approach to create an ImagePicker app in React Native. Following are the steps

  • Step 1 — Create a basic React Native app
  • Step 2 — Set up React Native Image Picker
  • Step 3 — Use React Native Image Picker to pick images in app

So let’s dive right in!

How to pick images from Camera & Gallery in React Nativeapp (2)

1. Create a basic React Nativeapp

Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App.

Assuming that you have node installed, you can use npm to install the react-native-cli command-line utility. Open the terminal and run the following command to the bottom

npm install -g react-native-cli

Now, let’s create a new React Native project, e.g. RNimagePicker

react-native init RNimagePicker

When the above command is done, open the main folder in your preferred editor. When we open the project in a code editor, its structure looks like this.

How to pick images from Camera & Gallery in React Nativeapp (3)

2. Set up React Native ImagePicker

To useReact Native Image Picker we need to install react-native-image-picker dependency.

Installation of Dependency

To add React Native Image Picker to our React Native Project, we need to run the following command at the root of the project

npm install react-native-image-picker --save
or
yarn add react-native-image-picker

This command will copy all the dependencies into your node_modules directory, You can find the directory in node_modules the directory named react-native-image-picker.

Linking of Dependency

To use react-native-image-picker library we have to link some dependencies in Android and iOS project files. So, we need to run the following command at the root of the project

react-native link react-native-image-picker

Permissions

You will also need to add some permissions on Android.

Now we will see how to give permissions in Android to use Camera and read Storage.

We are going using a Native API Camera and choose the image from the Gallery. So, we need to provide some permission to access the Camera and Gallery.

We are going to add the following permissions in the AndroidManifest.xml

Project → android → app → src → debug → AndroidManifest.xml

Your AndroidManifest.xmlshould look like this:

How to pick images from Camera & Gallery in React Nativeapp (4)

3.How to Use React Native ImagePicker

React Native Image Picker library provides an ImagePicker component in which you can set the options like the title of the picker, your custom buttons (name and title of the button) and storage options like skipBackup, etc..

Options that you get in React Native Image Picker are the following:

  • Title
  • Cancel ButtonTitle
  • Take PhotoButtonTitle
  • Choose From Library ButtonTitle
  • Custom Buttons
  • Camera Type
  • Media Type
  • Max Width
  • Max Height
  • Quality
  • Video Quality
  • Duration Limit
  • Rotation
  • Allows Editing
  • No Data
  • Storage Options
  • PermissionDenied

The code snippet of ImagePicker

In the above code, we will open an Image picker as you Click on “chooseImage” and will show the selected image on the Image component. Selection options are Camera and Gallery by default but we have also added a custom button which will simply generate an alert when we click on it.

How to pick images from Camera & Gallery in React Nativeapp (5)

Directly LaunchCamera

To implement the functionality of launching the Camera directly as you click on “Direct Launch Camera”, use the code below. It will directly open the camera and will show the clicked image on the Image Component.

How to pick images from Camera & Gallery in React Nativeapp (6)

Directly Launch ImageLibrary

To Directly Launch the Image Library you can use the following code below. It will directly open the Image Library and will show the Selected image on the Image Component.

How to pick images from Camera & Gallery in React Nativeapp (7)

App.js

This React Native module allows you to use native UI to select a photo/video from the device library as well as from the camera directly.

Your Screen should look like this:

How to pick images from Camera & Gallery in React Nativeapp (8)

Android Screens

Finally, for your reference all the screens for this image picker functionality will look similar to those shown below:

How to pick images from Camera & Gallery in React Nativeapp (9)

Conclusion

In this post, you learned in a quick fashion to implement React Native Image Picker in your React Native App. This enables your app to pick images/videos from the Camera and Gallery. It is one of the most important and basic functionalities that is needed in almost all the apps. Advanced functionalities are build up upon this basic core facility. You can find the complete code in this Github repo over here.

Next Steps

If you liked this blog, you will also find the following React Native blogs interesting and helpful. Feel free to ask any questions in the comment section

  • Firebase — Integrate Firebase | Analytics | Push notifications | Firebase CRUD
  • How To in React Native — Geolocation | Life cycle hooks | Image Picker | Redux implementation | Make API calls | Navigation | Translation | | | Google Vision | Pull to Refresh
  • Payments — Apple Pay | Stripe payments
  • Authentication — Google Login| Facebook login | Phone Auth | Twitter login
  • Create Instagram / Whatsapp Story Feature in React Native
  • React Native life cycle hooks | Implement Redux | Async actions with Redux
  • Create Awesome Apps in React Native using Full App

If you need a base to start your next React Native app, you can make your next awesome app using React Native Full App

How to pick images from Camera & Gallery in React Nativeapp (10)

How to pick images from Camera & Gallery in React Nativeapp (11)

Aditya Sharma

Full Stack Developer

Integrations

  • Firebase
  • Capacitor
  • Cordova
  • Socket
  • Sentry
  • Redux
  • Bot

UI/UX

  • Dark mode
  • Dev tools

Authentication

  • Google
  • Facebook
  • Twitter
  • Anonymous
  • Passwordless
  • Phone
  • Email

Features

  • Maps
  • Push Notifications
  • Camera
  • Contacts
  • APIs
  • SMS
  • Chat
  • Localization
  • PDF
  • Geolocation
  • PWAs
  • RTL

Payments

  • Paypal
  • Stripe
  • Braintree
  • Apple pay

Cloud

  • AWS
  • Heroku
  • Firebase functions
  • Node JS

Testing

  • Unit testing

How to pick images from Camera & Gallery in React Nativeapp (12)

ENAPPD

Ionic, React native, Vue, Flutter and

Firebase App starters, themes and templates

CONNECT WITH US

About Enappd | Terms | Privacy Policy

All rights reserved © Enappd 2018-2022

Browse Templates and Starters

Ionic 6 Starters React Native Starters Firebase Starters Free Starters Full App Starters

BestSellers

Ionic 6 Full App - Angular Capacitor Ionic 6 Full App - React Capacitor Ionic 6 Full App - Vue Capacitor Ionic 5 Full App - Angular Cordova Ionic 5 Taxi Booking Complete Platform Ionic 5 Grocery Shopping Complete Platform

Other Links

Privacy Policy Terms and Conditions Licensing Options

How to pick images from Camera & Gallery in React Native app (2024)

FAQs

How to pick images from Camera & Gallery in React Native app? ›

For picking the image in React Native, we will use a popular and superior library called react-native-image-picker . This provides the ImagePicker component in which you can provide the image picking option from Gallery or Camera.

How to pick images from camera & gallery in react-native? ›

For picking the image in React Native, we will use a popular and superior library called react-native-image-picker . This provides the ImagePicker component in which you can provide the image picking option from Gallery or Camera.

How to build an image picker using react-native image crop picker? ›

Building an Avatar Profile Update

js file, import the library: import ImagePicker from 'react-native-image-crop-picker'; We can use the library to select an image from the gallery or take a new one. This can be done by calling the openPicker or openCamera functions, respectively.

What is an image picker? ›

chrome extension named image picker version. This extension is a tool that save images from web page This is good for web page to prevent right-click to download image source https://github.com/bluemirr5/image-picker2.

How to upload an image from a gallery in react-native? ›

To handle image uploads we need to set the encoding type to multipart/form-data which means we need to format our data differently. Thus the createFormData function. This function will go ahead and take the image we selected and add it to the photo field of the form data with the required info.

How do I get an image from assets folder in react-native? ›

React-native images can be loaded from the app's native assets catalog (drawables on android and Images. xcassets on iOS) by providing source={{uri: "image_name_without_suffix"}} . This method of loading performs much better than loading via require("../path/to/image. png") .

Top Articles
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 5894

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.