title: Compressing an Image before Uploading it to Firebase Storage
body: <p>I am trying to Compress an Image before Uploading it to <code>Firebase Storage</code> using <code>SiliCompressor</code> library , but it seems  not working , the <code>ProgressDialog</code> doesn't stop.  What i first did was to pick the Image from the Gallery  into an ImageButton  by clicking an ImageButton. Below is my code.</p>
  
  <pre><code>imageSelect.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
                  galleryIntent.setType("image/");
                  startActivityForResult(galleryIntent, GALLERY_REQUEST);
              }
          });
  
  ---------------------------------------------------------------------
  
   @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == GALLERY_REQUEST &amp;&amp; resultCode == RESULT_OK) {
  
  
              imageUri = data.getData();
  
             // imageSelect.setImageBitmap(BitmapFactory.decodeFile(imageSelectFile.getAbsolutePath()));
          //    Compressor com = Compressor.getDefault(this).compressToFile(imageFile);
             // imageSelect.setImageURI(imageUri);
              Picasso.with(c).load(imageUri).fit().into(imageSelect);
  
          }
      }
  </code></pre>
  
  <p>So now am having a Method <code>startPosting()</code> which Uploads data By a click of  Button to Firebase Storage.
  Below is my code. </p>
  
  <pre><code> private void startPosting() {
          mProgress.setMessage("Uploading Image...");
          //Compressing an Image ....
          String stringUri= imageUri.toString();
          Uri uri_image_final;
          //String filePath = SiliCompressor.with(getApplicationContext()).compress(stringUri);
          String filePath = SiliCompressor.with(getApplicationContext()).compress(stringUri, true);
          uri_image_final = Uri.parse(filePath);
          System.out.println("Whats here :" +
                  ""+ uri_image_final);
  
          final String title_val = mPostTitle.getText().toString().trim();
          final String desc_val = mPostDesc.getText().toString().trim();
          if (!TextUtils.isEmpty(title_val) &amp;&amp; !TextUtils.isEmpty(desc_val) &amp;&amp; filePath != null) {
              mProgress.show();
              StorageReference filepath = mStorage.child("BlogImages").child(uri_image_final.getLastPathSegment());
              filepath.putFile(uri_image_final).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                  @Override
                  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  
  
                      Uri downloadUri = taskSnapshot.getDownloadUrl();
                      DatabaseReference newPost = mDatabase.push();
                      DatabaseReference c = mDatabase.push();
                      newPost.child("EventTitle").setValue(title_val);
                      newPost.child("EventDescription").setValue(desc_val);
                      newPost.child("EventImage").setValue(downloadUri.toString());
                      newPost.child("PostId").setValue(c);
  
  
  
                      mProgress.dismiss();
                      startActivity(new Intent(PostActivity.this, MainActivity.class));
  
  
                  }
              }
  
  
              );
  
  
          } else if (TextUtils.isEmpty(title_val) &amp;&amp; TextUtils.isEmpty(desc_val) &amp;&amp; imageUri != null) {
              mProgress.show();
              StorageReference filepath = mStorage.child("BlogImages").child(uri_image_final.getLastPathSegment());
              filepath.putFile(uri_image_final).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                  @Override
                  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
  
  
                      Uri downloadUri = taskSnapshot.getDownloadUrl();
                      DatabaseReference newPost = mDatabase.push();
                      newPost.child("EventTitle").setValue("");
                      newPost.child("EventDescription").setValue("");
                      newPost.child("EventImage").setValue(downloadUri.toString());
  
  
                      mProgress.dismiss();
                     // startActivity(new Intent(PostActivity.this, MainActivity.class));
                    Intent load=  new Intent(PostActivity.this,MainActivity.class);
                      load.putExtra(eventname,eventname);
                      startActivity(load);
  
  
                  }
              }
  
  
              );
  
          }
  
          else if (!TextUtils.isEmpty(title_val) &amp;&amp; !TextUtils.isEmpty(desc_val) &amp;&amp; imageUri== null){
  
              Toast.makeText(getApplicationContext(),"Please insert an Image and Upload ! ",Toast.LENGTH_LONG).show();
  
          }
      }
  </code></pre>
  
  <p>Now if you see in that Method , my essence was to Compress an Image which is loaded in the ImageButton, then Afterwards it Uploads to firebase.
  This is the line of <code>Silicon Compressor</code> which tries to compress an image loaded in the ImageButton. </p>
  
  <pre><code> String filePath = SiliCompressor.with(getApplicationContext()).compress(stringUri, true);
  </code></pre>
  
  <p>I got this lib from this link of Github.
  <a href="https://github.com/Tourenathan-G5organisation/SiliCompressor" rel="nofollow noreferrer">https://github.com/Tourenathan-G5organisation/SiliCompressor</a></p>
  
  <p>So where am i wrong please because the Image is not Uploading but i want it to Upload while it's compressed.</p>