I'm getting the var imgEnviar
, which gets the base64
that comes from the camera, and inserting into the JSON and sending it to the server with $ http with AngularJS. I want to know if it's really possible or if you have a better way to do this, because I need to send the camera image along with the form data.
Camera part with Cordova plugin
var imgEnviar;
function capturarImagem(){
navigator.camera.getPicture(onSuccess, onFail,
{
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA
}
);
}
function onSuccess(imageURL) {
var image = document.getElementById('htmlImagem');
image.src = "data:image/jpeg;base64," + imageURL;
//var imgEnviar = JSON.stringify(imageURL);
imgEnviar = image.src;
}
function onFail(message) {
alert('Erro: ' + message);
}
pate do agularJS
app.controller('formularioChamado', function($scope, $http) {
$(document).ready(function() {
$('select').material_select();
});
$scope.enviarForm = function(chamado){
$http({
url: 'https://modulosamu.herokuapp.com/chamado/store',
method: 'POST',
data: {
descricao: $scope.chamado.descricao,
img: imgEnviar,
latitude: latitude,
longitude: longitude,
},
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
}).
success(function (data) {
$scope.success = true;
alert(data);
$scope.user = {};
}).
error(function (data) {
$scope.error = true;
});
}
});