I want to store an image(from url) into a sqlite database.
For that I use:
db = new DataBase(getApplicationContext());
URL url = new URL(\"http://sr
for a ionic project
var imgURI = "";
var imgBBDD = ""; //sqllite for save into
function takepicture() {
var options = {
quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
imgURI = "data:image/jpeg;base64," + imageData;
imgBBDD = imageData;
}, function(err) {
// An error occured. Show a message to the user
});
}
And now we put imgBBDD into SqlLite
function saveImage = function (theId, theimage){
var insertQuery = "INSERT INTO images(id, image) VALUES("+theId+", '"+theimage+"');"
console.log('>>>>>>>');
DDBB.SelectQuery(insertQuery)
.then( function(result) {
console.log("Image saved");
})
.catch( function(err)
{
deferred.resolve(err);
return cb(err);
});
}
A server side (php)
$request = file_get_contents("php://input"); // gets the raw data
$dades = json_decode($request,true); // true for return as array
if($dades==""){
$array = array();
$array['error'] = -1;
$array['descError'] = "Error when get the file";
$array['logError'] = '';
echo json_encode($array);
exit;
}
//send the image again to the client
header('Content-Type: image/jpeg');
echo '';