title: How to Save base64 encoded image into MYSQL database using API in android
body: <p>Variable within the <code>onActivityResult</code> method and <code>bitmapToBase64(Bitmap bitmap)</code> method variables <strong>cant be access outside</strong>,<br>It storing <strong>null value</strong> in Mysql database while passing through url in android.    </p>
  
  <p><strong>For Example</strong>: In below code I am storing encoded image base64String in encoderes.<br>
  But while try to access from outside the method and while passing the encoded String through url. 
  It saves as <strong>null</strong> in database.</p>
  
  <pre><code>public String bitmapToBase64(Bitmap bitmap) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 70, byteArrayOutputStream);
  byte[] byteArray = byteArrayOutputStream.toByteArray();
  encoderes = Base64.encodeToString(byteArray, Base64.DEFAULT);
  encodedImage.setImgStr(encoderes);
  encodestr.setText(encoderes);
  
  return encoderes; }
  </code></pre>
  
  <p><strong>Encode code snippet</strong> </p>
  
  <pre><code>   @Override 
     public void onActivityResult ( int requestCode, int resultCode, Intent 
     data)
     {
      if (requestCode == CAMERA_REQUEST &amp;&amp; resultCode == Activity.RESULT_OK) {
      Uri imageUri = data.getData();
      imageView.setImageURI(imageUri);
      imageView.buildDrawingCache();
      Bitmap bmap = imageView.getDrawingCache();
      bitmapToBase64(bmap);} else if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK ) {
      Uri imageUri = data.getData();
      imageView.setImageURI(imageUri);
      imageView.buildDrawingCache();
      Bitmap bmap = imageView.getDrawingCache();
      bitmapToBase64(bmap);
  
      //Bitmap image = (Bitmap) data.getExtras().get("data");
  
  } }                                                                    
  public String bitmapToBase64(Bitmap bitmap) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 70, byteArrayOutputStream);
  byte[] byteArray = byteArrayOutputStream.toByteArray();
  encoderes = Base64.encodeToString(byteArray, Base64.DEFAULT);
  encodedImage.setImgStr(encoderes);
  encodestr.setText(encoderes);
  
  return encoderes; }
  </code></pre>