0

Hey everyone I know that its a controversial topic about storing either the image or the path to the image in the database however for this particular application when the user takes the picture I do not want them to be able to access it and with the way I transmit data to the server I need to send the blob.

Does anyone have a function that will take a picture and save it straight into a column in the sqlite database as a blob?

Thanks, Currently I only have the following functions to handle images:

var pictureSource;  
var destinationType;

function onPhotoDataSuccess(imageData) {
    console.log("* * * onPhotoDataSuccess");
    var cameraImage = document.getElementById('cameraImage');
    cameraImage.style.visibility = 'visible';
    cameraImage.src = "data:image/jpeg;base64," + imageData;
}

function take_pic() {
    navigator.camera.getPicture(onPhotoDataSuccess, function(ex) {
        alert("Camera Error!");
    }, { quality : 30, destinationType: Camera.DestinationType.DATA_URL });
}

Thanks again everyone!

user1857654
  • 183
  • 1
  • 5
  • 22

1 Answers1

1

I found this: Phonegap Database problem - storing images in the database

there is an answer to it so that should do the trick for you.

a raw example:

function onPhotoDataSuccess(imageData) {                
   // Get image handle
   var smallImage = document.getElementById('smallImage');

   // Unhide image elements
   smallImage.style.display = 'block';
   smallImage.src = imageData;

   /* do something else with imageData :) */

}

Read this too please:

http://docs.phonegap.com/en/1.0.0/phonegap_camera_camera.md.html

This is a part of it, but please read before that too ;)

You can do whatever you want with the encoded image or URI, for example:

Render the image in an tag (see example below) Save the data locally (LocalStorage, Lawnchair, etc) Post the data to a remote server

Community
  • 1
  • 1
Daniel
  • 2,002
  • 5
  • 20
  • 32
  • What I'm trying to do though is edit my onPhotoDataSuccess function so the picture is saved directly into my images table. Also the phonegap link you supplied is down :( 404. Any idea how to do that? – user1857654 Dec 21 '12 at 18:17
  • I believe that the link i posted to you have the answer, but it will require that you write it into your own code ofc :) – Daniel Dec 21 '12 at 18:28
  • i remade my answer, try and use the imageData variabel that already are available. And create your database with a blob element aswell :) – Daniel Dec 21 '12 at 18:31
  • Btw i just used the link, not sure why you cant see it, but it works :) – Daniel Dec 21 '12 at 18:34