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

react-native-photo-upload

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-photo-upload

Cross platform photo upload component for react native

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
283
increased by356.45%
Maintainers
2
Weekly downloads
 
Created
Source

react-native-photo-upload

screenshot

This component handles all the hassle in dealing with photos in react native, it's built on top of react-native-image-picker, react-native-image-resizer and react-native-fs it takes an image component and upon click, you get the image picker prompt, get the base64 string of the image and the image source changes to whatever image was picked.

Installing

npm or yarn install

npm install react-native-photo-upload --save

or

yarn add react-native-photo-upload

Automatic Installation

link react-native-image-picker, react-native-image-resizer and react-native-fs which the component depends on

react-native link react-native-image-picker
react-native link react-native-image-resizer
react-native link react-native-fs
The following steps are required by react-native-image-picker for both Android and IOS even with automatic linking

Android

  • Update the android build tools version to 2.2.+ in android/build.gradle (required step by `react-native-image-picker):
buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.+' // <- USE 2.2.+ version
    }
    ...
}
...
  • Update the gradle version to 2.14.1 in android/gradle/wrapper/gradle-wrapper.properties:
 ...
 distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
  • Add the required permissions in AndroidManifest.xml:
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

IOS

For iOS 10+, Add the NSPhotoLibraryUsageDescription, NSCameraUsageDescription, and NSMicrophoneUsageDescription (if allowing video) keys to your Info.plist with strings describing why your app needs these permissions. Note: You will get a SIGABRT crash if you don't complete this step

<plist version="1.0">
  <dict>
    ...
    <key>NSPhotoLibraryUsageDescription</key>
    <string>photo</string>
    <key>NSCameraUsageDescription</key>
    <string>camera</string>
  </dict>
</plist>

Manual Installation

check the docs of each library on how to link manually.

  • react-native-image-picker
  • link react-native-image-resizer
  • react-native-fs

Usage

Wrap your default image inside the PhotoUpload component, the component wraps the image with TouchableOpacity, on press it will trigger the image picker prompt. after selecting a new image from the picker, the image source will get replaced with the new image base64 string as uri

 <PhotoUpload>
   <Image
     source={{
       uri: 'https://www.sparklabs.com/forum/styles/comboot/theme/images/default_avatar.jpg'
     }}
   />
 </PhotoUpload>

Example

 import { Image } from 'react-native'
 import PhotoUpload from 'react-native-photo-upload'

 <PhotoUpload
   onPhotoSelect={avatar => {
     if (avatar) {
       console.log('Image base64 string: ', avatar)
     }
   }}
 >
   <Image
     style={{
       paddingVertical: 30,
       width: 150,
       height: 150,
       borderRadius: 75
     }}
     resizeMode='cover'
     source={{
       uri: 'https://www.sparklabs.com/forum/styles/comboot/theme/images/default_avatar.jpg'
     }}
   />
 </PhotoUpload>

Props

PropTypeDescription
containerStyleObjectStyle object for the image container
photoPickerTitleStringTitle for the image picker prompt, default is 'Select Photo'
heightNumberthe resized image height, default is 300
widthNumberthe resized image width, default is 300
formatStringThe format desired of the resized image, 'JPEG' or 'PNG' default is 'JPEG'
qualityNumberThe quality of the resized image indicated by a number between 1 and 100, default is 80
onPhotoSelectFunctionfunction which takes the base64 string of the new image as parameter

Keywords

FAQs

Package last updated on 20 Sep 2017

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