Search code examples
javascriptandroidcordovaphonegap-plugins

How to open android gallery after taking picture?


Is there a way to open the device gallery like when clicking on an input of type file and select the picture just taked with the device camera?

My problem is that I already have an file input, but now when I click on it I open the camera to take a picture. Is it possible to open the device gallery after taking the picture to select the picture I just taken for uploading it?

Now I'm getting it on base 64 encoded. I don't wan't that, because I already have an php and ajax upload where I already use normal images.

My code:

$(document).ready(function(){
  $('#file_input').on('click', function(e){
    e.preventDefault();
    navigator.camera.getPicture(onSuccess, onFail, { 
      quality: 100,
      destinationType: Camera.DestinationType.DATA_URL
    });
    function onSuccess(imageData) {
      // here I can upload imageData to the server
    }
    function onFail(message) {
      alert('Failed because: ' + message);
    }
  });
})

Or is there a way to get the photo just taken just like when I have a file input and select from gallery?

EDIT:

I've found another solution to my problem without having to open the gallery after taking the picture.

I get the image like now, in base64 format. I pass it to PHP using AJAX and then I'm decoding it using base64_decode(), and then a save it to the server using file_get_contents(), after that a pretty basic save path to the database. And that's it. Success.

Although I can't seem too find the photo taken on my device. Has anyone an idea where it could be stored. Or I have to store it manually after taking the picture?


Solution

  • I think you are fine with android side.You are getting image in base64 encoded.Now here is the link where you can found how to move image to desired location on server and when you will finished with that you can store path to that folder in database

    By this way your database performance will not affected because you are gonna store only paths in database And for getting captured image directly follow this link and see answer given by Augusto Picciani