Android : Phongap upload photo from camera

on Thursday, April 16, 2015


I'm french, so sorry for my ( so bad ) english ! I need some help, I must do an application who send photo from camera to my wamp server, I try with phonegap, but I've a problem, I try this code but, he always make me the alert "Ups. Something wrong happens!" And I don't know why because the code seems to be good... I think it's certainly a configuration in wamp... Help me please,



function clearCache() {
navigator.camera.cleanup();
}

var retries = 0;
function onCapturePhoto(fileURI) {
var win = function (r) {
clearCache();
retries = 0;
alert('Done!');
}

var fail = function (error) {
if (retries == 0) {
retries ++
setTimeout(function() {
onCapturePhoto(fileURI)
}, 1000)
} else {
retries = 0;
clearCache();
alert('Ups. Something wrong happens!');
}
}

var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.params = {}; // if we need to send parameters to the server request
var ft = new FileTransfer();
ft.upload(fileURI, encodeURI("http://192.168.1.22/PULZ/"), win, fail, options);
}

function capturePhoto() {
navigator.camera.getPicture(onCapturePhoto, onFail, {
quality: 100,
destinationType: destinationType.FILE_URI
});
}


Thank you for your help ! :)


0 comments:

Post a Comment