Ionic Get image from Gallery

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.

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

1 Like

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

Ionic Native. ngCordova is for Ionic 1.

3 Likes

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


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

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
);
4 Likes

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

1 Like

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.

4 Likes

@sava999 your solution works for me! thxā€¦

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

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

Thanks.

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

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

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

where to apply this code? @sava999