RED.Skull
RED.Skull

Reputation: 1736

Sending base64 image to server in phonegap

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

Answers (2)

Sivailango
Sivailango

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

Gajotres
Gajotres

Reputation: 57309

Because you are using a Phonegap a cross domain call should not be a problem.

  1. Is your picture taken successfully and can you see it?
  2. Check you are receiving data on a server side.
  3. In case there's a problem with a point 1. check if you can send any REST request to your server
  4. Check that you have enough permission to access an internet from your mobile app

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

Related Questions