title: JSON 64bit decoding bitmap from android to place in mysql BLOB
body: <p>Sending a image to mysql using android, json and php</p>
  
  <p>I was able to get my bitmap converted to a properly formatted string using </p>
  
  <p><a href="http://mobile.cs.fsu.edu/converting-images-to-json-objects/" rel="nofollow">converting-images-to-json-objects</a></p>
  
  <p>Here is the code in android </p>
  
  <pre><code>JSONObject values = new JSONObject();
              values.put(KEY_CONTRACTUUID, con.UUID);
              ...
              if (con._sig != null) {
                  String encodedImage = getStringFromBitmap(con._sig);
                  values.put(KEY_CONTRACTSIGIMAGE, encodedImage);
  
  
      private static String getStringFromBitmap(Bitmap bitmapPicture) {
          /*
           * This functions converts Bitmap picture to a string which can be
           * JSONified.
           */
          final int COMPRESSION_QUALITY = 100;
          String encodedImage;
          ByteArrayOutputStream byteArrayBitmapStream = new ByteArrayOutputStream();
          bitmapPicture.compress(Bitmap.CompressFormat.PNG, COMPRESSION_QUALITY,
                  byteArrayBitmapStream);
          byte[] b = byteArrayBitmapStream.toByteArray();
          encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
          return encodedImage;
      }
  </code></pre>
  
  <p>now that it is in base64 and a string I need to retrieve it properly to place in my BLOB in mysql</p>
  
  <p>I am not using namevalue pairs or any of that nonsense - simply send it as json and get the json string like so:</p>
  
  <pre><code>$json = json_decode($HTTP_RAW_POST_DATA,true);
  echo var_dump(HTTP_RAW_POST_DATA);
  ...
  $varsigimage = $json['sigimage'];
  
  $formatedJSONimage = "{'sigimage': '$varsigimage'}";
  var_dump($formatedJSONimage);
  $sigImagedecoded = json_decode($formatedJSONimage);
  var_dump($sigImagedecoded);
  </code></pre>
  
  <p>i need to call json_decode on the image to get it out of 64bit to place in the blob correct?</p>
  
  <p>However to do this I need to use the function json_decode, but json_decode assumes I will give it a JSONObject, and since I have many more objects in my $json object, i need to recreate a single JSON object with just the image inside of it, and pass that to the json_decode
  but it retuns json_error of type SYNTAX</p>
  
  <p>What am I doing wrong, What is the correct approach of converting the base64 string to a blob?</p>
  
  <p>and yes, I am going to have the same question on getting it out of the blob back to a base64 string</p>