Ionic Get image from Gallery


#1

Hi, Im trying to pick image from Gallery and upload to Firebase.so Can any one help me to get image from phone Gallery using Ionic 2.


#2

You can use the Camera plugin and set the sourceType to pull in from the users photo library, rather than using the camera itself.


#3

Want I use ionic-native plugin or ng-cordova camera plugin?


#4

Ionic Native. ngCordova is for Ionic 1.


#5

Thank you.any way im big fan of your blog. :slight_smile:


#6


use this image picker plug-in. It uses ng-cordova . I have used this in 2 of my ionic applications.


#7

It is very simple to get image from gallery.

First install plugin:
ionic plugin add cordova-plugin-camera

Than use this:

let options = {
    destinationType   : Camera.DestinationType.DATA_URL,
    sourceType        : Camera.PictureSourceType.PHOTOLIBRARY
};

navigator.camera.getPicture(
    (data)  => {
      let image = "data:image/jpeg;base64," + data;
    },
    (error) => {  },
    options
);

#8

thank you, very simple solution, no need to add image picker plugin


#9

Well, with that solution you can only pick one image at a time. With the image picker plugin you can select multiple images at a time. So it depends on what you need really.


#10

@sava999 your solution works for me! thx…


#11

how do I get it to show in an <img afterwards? using “image” as the source? or “data:image/jpeg;base64,”


#12

this works for me as well.
And the picture layout looks better than image picker in ios.

Thanks.


#13

Hi, I’m also trying to upload Image from Gallery and select and save it into Firebase. I’m able to go to Gallery and select a Pic. But I’m not able to save it in firebase. Could you please help me to upload image in to firebase from Photo library in Ionic2. Thanks


#14

Hey if you still need help with posting the image to firebase check out my repo here: https://github.com/Matt4759/Ionic3-FirebaseImageSharing


#15

Hi… I used ionic native camera and i can get images using only camera. could not get images from the library.
‘camera option’ cant add to the app.module.ts . ;; I am using ionic 3


#16

where to apply this code? @sava999