Skip to content

ingenuity-ph/react-native-image-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-image-uploader NPM version Build Status

React Native module that uses Expo functions to Open Camera and Camera Roll and also upload to API using react-native-api-client-wrapper

Dependencies

Pure React Native Project compiled by Expo

$ npm install --save react-native-api-client-wrapper

Installation

$ npm install --save react-native-image-uploader

Usage

import { ImageUploader } from 'react-native-image-uploader'

openCamera = async () => {
  /**
   * 
   * @param {*} aspectratio should be an array ex. [1,1] [3,4]
   */
  ImageUploader.openCamera(aspectratio).then((result) => {
    /** result
     * Object {
     * base64: base64code,
     * cancelled: false
     * height: 123,
     * type: image
     * uri: directoryfromstorage
     * width: 123
     * }
     */
    }).catch((error) => {
    //error
    })
}

openCameraRoll = async () => {
  /**
   * 
   * @param {*} aspectratio should be an array ex. [1,1] [3,4]
   */
  ImageUploader.openCameraRoll(aspectratio).then((result) => {
    /** result
     * Object {
     * base64: base64code,
     * cancelled: false
     * height: 123,
     * type: image
     * uri: directoryfromstorage
     * width: 123
     * }
     */
    }).catch((error) => {
    //error
    })
}

uploadtoAPi(base64) {
  let url = 'https://api.imgur.com/3/image';
  let headers = {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': 'this is your Token'
  };
  let params = {
    image: base64,
  };

    ImageUploader.uploadtoServer(url, headers, params).then((response)  => {
      //response
    }).catch((error) => {
      //error
    })
}

Contributing

  1. Fork repository
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

License

MIT