title: Need to convert Image clicked from Phone into base 64 string and send it to server
body: <p>The user clicks image from his phone (using camera 2 api). I am storing it on users device using following function. I am not using bitmap.</p>
  <pre><code>private void dispatchTakePictureIntent() {
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      // Ensure that there's a camera activity to handle the intent
      if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
          // create the file where the photo should go
          File photoFile = null;
          try {
              photoFile = createImageFile();
          } catch (IOException e) {
              // Error message
              Toast.makeText(this, &quot;Error occured while creating the file&quot;, Toast.LENGTH_SHORT).show();
          }
  
          //Continue only if the File was successfully created
          if (photoFile != null) {
              Uri photoURI = FileProvider.getUriForFile(this, &quot;com.valuefintech.android.fileprovider&quot;, photoFile);
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
              startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
          }
      }
  }
  
  private File createImageFile() throws IOException {
      String timestamp = new SimpleDateFormat(&quot;yyyyMMdd_HHmmss&quot;).format(new Date());
      String imageFileName = &quot;JPEG_&quot; + timestamp + &quot;_&quot;;
      File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
      File image = File.createTempFile(
              imageFileName,
              &quot;.jpg&quot;,
              storageDir
      );
  
      //save a file: path for use with ACTION_VIEW intents
      currentPhotoPath = image.getAbsolutePath();
      return image;
  }
  </code></pre>
  <p>and then it displays the image on imageview using following code</p>
  <pre><code>if(requestCode == CAMERA_REQUEST_CODE &amp;&amp; resultCode == Activity.RESULT_OK) {
  
              File f = new File(currentPhotoPath);
  
              idImage.setImageURI(Uri.fromFile(f));
              Log.d(&quot;tag&quot;, &quot;Absolute url of image is &quot; + Uri.fromFile(f));
  
          byte[] b = new byte[(int) f.length()];
          try {
              FileInputStream fileInputStream = new FileInputStream(f);
              fileInputStream.read(b);
              for (int j = 0; j &lt; b.length; j++) {
                  System.out.print((char) b[j]);
              }
          } catch (FileNotFoundException e) {
              System.out.println(&quot;File Not Found.&quot;);
              e.printStackTrace();
          } catch (IOException e1) {
              System.out.println(&quot;Error Reading The File.&quot;);
              e1.printStackTrace();
          }
  
          byte[] byteFileArray = new byte[0];
          try {
              byteFileArray = FileUtils.readFileToByteArray(f);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          String base64String = &quot;&quot;;
          if (byteFileArray.length &gt; 0) {
              base64String = android.util.Base64.encodeToString(byteFileArray, android.util.Base64.NO_WRAP);
              Log.i(&quot;File Base64 string&quot;, &quot;IMAGE PARSE ==&gt;&quot; + base64String);
          }
  
              Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
              Uri contentUri = Uri.fromFile(f);
              mediaScanIntent.setData(contentUri);
              this.sendBroadcast(mediaScanIntent);
  
      }
  </code></pre>
  <p>The problem is I am not able to convert the image into Base64 so that I can upload it to my server.</p>