Download the base64 image to the php server and register in MySql

advertisements

From my phone, I am taking a picture with ngcordova and convert it to base64. This works perfectly and can be displayed on my phone app just after it.

Now, I am trying to send the base64 string to my PHP server with the $http from angularjs, but for some reason, it does not receive it. Here is the code.

var request = $http({
  method: "post",
  url: mainUrl + "spus.php",
  params: {
    action: "saveLocationPicture",
    locationPicture: spuInfo.locationPicture  <-- "data:image/png;base64,/9j/44AQSk..."
  }
});

I said that the php server does not receive it, but I think it is not true. Why? Because if I send a shorter string (less than 835 characters), the php server receives it and I can save it to the MySql database. For test, I created 2 columns in the MySql table. One is of type LongBlob and the other one LongText. It should have plenty of room. ;-)

First of all, is there any limitation to the string that can be sent to the $http "params"?

If so, what is the limit?

Maybe it is my PHP server configuration that cannot handle the long base64 string? What do you think?

Thanks

******** UPDATE *******

Hi all,

I found a partial solution so far and wanted to share with you.

I can now send my big base64 image to my php server by doing that:

    var request = $http({
      method: "post",
      url: mainUrl + "spus.php",
      data: {
        action: "saveLocationPicture",
        hw_id: spuInfo.hw_id,
        locationPicture: spuInfo.locationPicture
      }
    });

And, in my php code:

    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);

    $action2 = $request->action;
    $hw_id2 = $request->hw_id;
    $locationPicture = $request->locationPicture;

Now, the only problem that I see is this in the Chrome debug console view:

GET data:image/png;base64,/9j/4AAQSkZJRgABAgAAAQABAADFQWERTYUIOPHGJTIYKHMBFHTYF…kZJRgABAgAAAQABAAD//gAEKgD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQFFFFFFFFFFF net::ERR_INVALID_URL

Does somebody know why I am having that?

Thanks


Why don't you try the Cordova File Transfer Plugin to upload your image file to the server, retrieve the file using $_FILE , covert it into blob object and store it.