title: Save base64encoded image to server-side database as BLOB
body: <p>I am taking a photograph from within my <strong>Android app</strong> using this code:</p>
  
  <pre><code>if (requestCode == CAMERA_REQUEST &amp;&amp; resultCode == RESULT_OK){
          photo = (Bitmap) data.getExtras().get("data");
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          photo.compress(Bitmap.CompressFormat.JPEG, 40, baos);
          byte[] photoByte = baos.toByteArray();
          encodedImage = Base64.encodeToString(photoByte,Base64.DEFAULT);
      }
  </code></pre>
  
  <p>I am sending this String <code>encodedImage</code> to my PHP server through POST and receiving it to <code>$encodedImage</code>. I have a database where I have a field <code>myImage</code> of type <code>MEDIUMBLOB</code>. I tried to save the <code>encodedimage</code> in <code>myImage</code> but it is saved as corrupted image. I tried to save as <code>base64_decode($encodedImage)</code> but somehow that didn't work either. </p>
  
  <p>I want three things to be done:</p>
  
  <ul>
  <li><p>Save image to server-side database (BLOB) </p></li>
  <li><p>Show image to a webpage </p></li>
  <li><p>Send it back to the Android app.</p></li>
  </ul>
  
  <p>I am facing issues in <strong>understanding the conversion</strong> of image required in different formats for the above tasks.</p>
  
  <p>For my current project, I don't want to save my image to folder and give link to the database, so that option is closed for me.</p>
  
  <p>My PHP code to save the image:</p>
  
  <pre><code>$baseImage = $_POST['baseImage'];
  $blobImage = base64_decode($baseImage);
  $query = "INSERT INTO `complaints`(`myImage`,...) VALUES ('$blobImage',...)"
  $result = mysqli_query($conn,$query);
  </code></pre>