0

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?

Ionut
  • 10,707
  • 4
  • 40
  • 69

2 Answers2

1

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

Community
  • 1
  • 1
Dhiraj
  • 848
  • 2
  • 12
  • 25
  • You mean to save the image encoded in base64 in the database? – Ionut May 12 '16 at 08:12
  • @Anonymous No no you will have one folder at server side put all images into that folder and save path to that folder into database – Dhiraj May 12 '16 at 08:14
  • @Anonymous and how can you put the images selected and uploaded from android side is well explained in first link – Dhiraj May 12 '16 at 08:15
  • @Anonymous did you find it usefull or not? – Dhiraj May 12 '16 at 08:48
  • Not quite. I already have php script and an ajax script to save the image path into database. I don't know how to get the path. Decoding the image in php is not returning the path of the image. It returns an encoded string of the image. – Ionut May 12 '16 at 08:52
  • @Anonymous you can change that script – Dhiraj May 12 '16 at 09:03
  • I changed it. It uploads the image but when I try to open it, says it too large or corrupt. And too large can't be, because is only 119 kb – Ionut May 12 '16 at 09:04
  • @Anonymous how you are trying to open it? – Dhiraj May 12 '16 at 09:06
  • I downloaded it from ftp and opening it on Windows 7 – Ionut May 12 '16 at 09:06
  • @Anonymous can you try with some small size image again? But in my case it works with 138 kb too. – Dhiraj May 12 '16 at 09:11
  • I got it working. It was because I was adding "data:image/jpeg;base64," to the encoded image – Ionut May 12 '16 at 09:12
  • @Anonymous happy to hear it.If it is working you can accept ans – Dhiraj May 12 '16 at 09:15
0

 $('#file_input').on('click', function(e){
    e.preventDefault();
    navigator.camera.getPicture(onSuccess, onFail, { 
      quality: 100,
      destinationType: Camera.DestinationType.FILE_URI,
   sourceType: 2, // 1 for camera, 2 for gallery
   allowEdit: true, // Can edit the pictures and lets the user pick gallery app
   mediaType: Camera.MediaType.PICTURE,
   encodingType: Camera.EncodingType.JPEG,
   popoverOptions: CameraPopoverOptions,
   // targetWidth: 500,
   // targetHeight: 500,
   saveToPhotoAlbum: false,
   correctOrientation: true // false: switches the height and width }); 
    });
    function onSuccess(imageData) {
      // here I can upload imageData to the server
    }
    function onFail(message) {
      alert('Failed because: ' + message);
    }
  });
DorkNstein
  • 126
  • 1
  • 4
  • I think you missunderstood me. I first need to take a picture with the camera and then open the gallery to get the photo I took. Now It only opens the tab to choose from gallery. – Ionut May 12 '16 at 07:41