Reputation: 1736
Trying to send the base64 image to server through restwebservice. Problem is i didnt get any error in logcat and its not hitting the server. Server url is correct. and i tested service using webapp its working fine. But in phonegap its problem
function Test() { alert(imgByte);
/**imgByte is in base64 format -->pic.src = "data:image/png;base64," + imageURI;
imgByte = pic.src;*/
$.ajax({
type : "POST",
url : IMGURL,
data : {
image : imgByte
},
delay : 3,
dataType : "text",
cache : false,
error : function(xhr, ajaxOptions, thrownError) {
debugger;
},
success : function(response, status, xhr) {
alert("haiSuccess1");
response = xhr.responseText;
var responseArray = JSON.parse(response);
if (responseArray.status == "success") {
alert("haiSuccess");
}
}
});
}
Upvotes: 0
Views: 6085
Reputation: 564
Its not Phonegap problem. By default your webserver (Server side code runnning on server), they restricted the Incoming data size (not file size ) to some fixed size. You should increase to get this to be work.
Upvotes: 0
Reputation: 57309
Because you are using a Phonegap a cross domain call should not be a problem.
This is a working code I used in one of my examples.
Javascript :
navigator.camera.getPicture(success, fail, {quality: 45, sourceType: src});
function success(imageData) {
var url = some_location;
var params = {image: imageData};
// send the data
$.post(url, params, function(data) {
alert('sent');
// Display the selected image on send complete
$('#image').attr('src', 'data:image/jpeg;base64,' + params['image']);
});
}
function fail(error) {
alert(error);
}
PHP :
<?php
if ($_REQUEST['image']) {
// convert the image data from base64
$imgData = base64_decode($_REQUEST['image']);
// rest of the code
}
?>
But my guess is you are receiving this error: Error 414 (Request-URI Too Large). You are trying to send to large picture. To fix this lower picture quality to lowest point and try to send it. If it works correctly then this is your problem.
Upvotes: 1