title: Compress image in webview before upload android kotlin
body: <p>I have created webview view in Android Kotlin with two options i.e. by opening file manager or camera help me add it before uploading from both options and compress data directly so the image size is small</p>
  <p>following code for <code>webChromeClient()</code></p>
  <pre><code>binding.webview.webChromeClient = object : WebChromeClient() {
              @SuppressLint(&quot;QueryPermissionsNeeded&quot;)
              override fun onShowFileChooser(
                  view: WebView,
                  filePath: ValueCallback&lt;Array&lt;Uri&gt;&gt;,
                  fileChooserParams: FileChooserParams
              ): Boolean {
                  mFilePathCallback?.onReceiveValue(null)
                  mFilePathCallback = filePath
                  var takePictureIntent: Intent? = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
                  if (takePictureIntent!!.resolveActivity(packageManager) != null) {
                      var photoFile: File? = null
                      try {
                          photoFile = createImageFile()
                          takePictureIntent.putExtra(&quot;PhotoPath&quot;, mCameraPhotoPath)
                      } catch (ex: IOException) {
                          Log.e(TAG, &quot;Unable to create Image File&quot;, ex)
                      }
                      if (photoFile != null) {
  //                        val stream = contentResolver.openInputStream(Uri.fromFile(photoFile))
  //                        val bitmap = BitmapFactory.decodeStream(stream)
  //                        val baos = ByteArrayOutputStream()
  //                        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos)
  //                        val path = MediaStore.Images.Media.insertImage(contentResolver, bitmap, &quot;Title&quot;, null)
                          mCameraPhotoPath = &quot;file:&quot; + photoFile.absolutePath
                          takePictureIntent.putExtra(
                              MediaStore.EXTRA_OUTPUT,
                              Uri.fromFile(photoFile)
                          )
                      } else {
                          takePictureIntent = null
                      }
                  }
                  val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT)
                  contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE)
                  contentSelectionIntent.type = &quot;image/*&quot;
                  val intentArray: Array&lt;Intent?&gt; = takePictureIntent?.let { arrayOf(it) } ?: arrayOfNulls(0)
                  val chooserIntent = Intent(Intent.ACTION_CHOOSER)
                  chooserIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
                  chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
                  chooserIntent.putExtra(Intent.EXTRA_TITLE, &quot;Image Chooser&quot;)
                  chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray)
                  startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE)
                  return true
              }
          }
  </code></pre>
  <p>Here's for the <code>onActivityResult()</code> function</p>
  <pre><code> override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
      if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
          super.onActivityResult(requestCode, resultCode, data)
          return
      }
      var results: Array&lt;Uri&gt;? = null
      if (resultCode == RESULT_OK) {
          if (data == null) {
              if (mCameraPhotoPath != null) {
                  results = arrayOf(Uri.parse(mCameraPhotoPath))
              }
          } else {
              val dataString = data.dataString
              if (dataString != null) {
                  results = arrayOf(Uri.parse(dataString))
              }
          }
  
      }
      mFilePathCallback!!.onReceiveValue(results)
      mFilePathCallback = null
  
     //        val newPath: String?
      if (requestCode == FILECHOOSER_RESULTCODE) {
          if (null == mUploadMessage) {
              return
          }
          val result: Uri?
          if (resultCode != RESULT_OK) {
              result = null
          } else {
              result = if (intent == null) mCapturedImageURI else intent.data
          }
  
          val storageDir = 
    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
      //            if (!storageDir.exists()){
      //                storageDir.mkdirs();
       //            }
          val file = File(
              storageDir, File.separator.toString() + &quot;IMG_&quot; + System.currentTimeMillis()
                  .toString() + &quot;.jpg&quot;
          )
  
          val newPath = getRealPathFromURI(this, result)
          //            newPath = if (result == mCapturedImageURI) {
          //                file.getAbsolutePath()
          //            } else {
          //                getRealPathFromURI(applicationContext, result)
          //            }
          val bMap = BitmapFactory.decodeFile(newPath)
          val out = Bitmap.createScaledBitmap(bMap, 150, 150, false)
          val resizedFile = File(storageDir, &quot;resize.png&quot;)
          var fOut: FileOutputStream? = null
          try {
              fOut = FileOutputStream(resizedFile)
              out.compress(Bitmap.CompressFormat.JPEG, 50, fOut)
              fOut.flush()
              fOut.close()
              bMap.recycle()
              out.recycle()
          } catch (e: Exception) {
          }
          mUploadMessage!!.onReceiveValue(Uri.fromFile(resizedFile))
          mUploadMessage = null
     //            resizedFile.delete();
      }
      return
  
  }
  </code></pre>
  <p>when running the code, the actual size of the running image, how to make it smaller or compress it before uploading</p>