1
I’m getting the hang of imgEnviar
, who receives the base64
coming from the camera, and inserting into the JSON and sending to the server with $http with Angularjs. I want to know if it’s really possible or if there’s a better way to do it, 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;
});
}
});
Use a service I did in Angularjs https://github.com/marangonijunior/bananaJs/blob/master/bananaJs.js Very quiet to access some plugins. *You need to have the plugins installed ok. Success!
– user57434