title: Upload image and description on Firebase using Kotlin
body: <p>At the moment, my application uploads images on firebase, but I want to add a description of that image too. After that, I need to retrieve both image and description on Home Page. But I am stuck at the part where I also add upload the description of the image..</p>
  <pre><code>package com.giveandshareauth
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.app.Activity
  import android.app.ProgressDialog
  import android.content.Intent
  import android.net.Uri
  import android.nfc.Tag
  import android.provider.MediaStore
  
  import android.text.TextUtils
  import android.util.Log
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.Toast
  import androidx.fragment.app.Fragment
  import com.giveandshareauth.Fragments.HomeFragment
  import com.giveandshareauth.Fragments.PostFragment
  import com.giveandshareauth.R
  import com.google.android.gms.tasks.OnCompleteListener
  import com.google.firebase.auth.FirebaseAuth
  import com.google.firebase.database.FirebaseDatabase
  import com.google.firebase.storage.FirebaseStorage
  import com.google.firebase.storage.StorageReference
  import com.google.firebase.storage.StorageTask
  import kotlinx.android.synthetic.main.fragment_post.*
  import com.theartofdev.edmodo.cropper.CropImage
  
  import com.google.android.gms.tasks.Continuation
  import com.google.android.gms.tasks.Task
  import com.google.firebase.storage.UploadTask
  import kotlinx.android.synthetic.main.activity_post.*
  import kotlinx.android.synthetic.main.activity_registration.*
  import kotlinx.android.synthetic.main.fragment_post.PostImage
  import kotlinx.android.synthetic.main.activity_post.PostInfo as PostInfo1
  
  class PostActivity : AppCompatActivity() {
  
      lateinit var filepath : Uri
      private var imageUri: Uri? = null
      private var storagePostImages: StorageReference? = null
  
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_post)
          storagePostImages = FirebaseStorage.getInstance().reference
  
          upload.setOnClickListener(){
              uploadFiles()
          }
  
          publish.setOnClickListener(){
              publishFiles()
  
  
          }
      }
  
      private fun uploadFiles() {
          var i = Intent()
          i.setType(&quot;image/*&quot;)
          i.setAction(Intent.ACTION_GET_CONTENT)
          startActivityForResult(Intent.createChooser(i, &quot;Choose an image&quot;), 111)
  
  
      }
  
      private fun publishFiles(){
          
  
          if(filepath != null){
              var pd = ProgressDialog(this)
              pd.setTitle(&quot;Upload&quot;)
              pd.show()
              var imageRef = FirebaseStorage.getInstance().getReference().child(&quot;Images/&quot;+System.currentTimeMillis()); //Every time an image will be uploaded, it will have a unique name in Firebase
              imageRef.putFile(filepath)
                      .addOnSuccessListener {param -&gt;
                          pd.dismiss()
                          Toast.makeText(applicationContext,&quot;File uploaded&quot;,Toast.LENGTH_LONG).show()
  
                      }
                      .addOnFailureListener {param -&gt;
                          pd.dismiss()
                          Toast.makeText(applicationContext, param.message,Toast.LENGTH_LONG).show()
  
                      }
                      .addOnProgressListener {param -&gt;    // how much percent of the file is uploaded
                          var progress = (100.0 * param.bytesTransferred) / param.totalByteCount
                          pd.setMessage(&quot;Uploaded ${progress.toInt()}%&quot;)
  
                      }
  
                          imageRef.downloadUrl
                      }
  
          }
  
  
          // val intent = Intent(this, HomeFragment::class.java)
          // startActivity(intent);
  
  
      override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
          if(requestCode==111 &amp;&amp; resultCode == Activity.RESULT_OK &amp;&amp; data != null){
              filepath = data.data!!
              var bitmap = MediaStore.Images.Media.getBitmap(contentResolver,filepath)
              PostImage.setImageBitmap(bitmap)
          }
  
      }
  
  
  
  }
  </code></pre>
  <p>The activity has an upload and a publish button also an ImageView and an EditText
  The publish button uploads the image on firebase, I assume I should add a new button that uploads the whole thing after the description is added.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;FrameLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.Fragments.HomeFragment&quot;&gt;
  
      &lt;RelativeLayout
          android:id=&quot;@+id/layoutID&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  
          &lt;!-- TODO: Update blank fragment layout --&gt;
          &lt;com.google.android.material.appbar.AppBarLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:id=&quot;@+id/app_bar_layout_post&quot;
              android:background=&quot;@android:color/white&quot;
              &gt;
  
              &lt;androidx.appcompat.widget.Toolbar
                  android:id=&quot;@+id/post_toolbar&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;50dp&quot;
                  android:layout_marginTop=&quot;4dp&quot;
                  android:layout_marginLeft=&quot;6dp&quot;
                  android:layout_marginRight=&quot;6dp&quot;
                  android:background=&quot;@android:color/white&quot;
                  &gt;
  
                  &lt;RelativeLayout
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;wrap_content&quot;&gt;
  
                      &lt;ImageView
                          android:id=&quot;@+id/close_post_btn&quot;
                          android:layout_width=&quot;20dp&quot;
                          android:layout_height=&quot;30dp&quot;
                          android:layout_alignParentStart=&quot;true&quot;
                          android:src=&quot;@drawable/close&quot;
                          /&gt;
  
                      &lt;ImageView
                          android:id=&quot;@+id/save_post_btn&quot;
                          android:layout_width=&quot;30dp&quot;
                          android:layout_height=&quot;30dp&quot;
                          android:layout_marginRight=&quot;15dp&quot;
                          android:layout_alignParentEnd=&quot;true&quot;
                          android:src=&quot;@drawable/save&quot;
                          /&gt;
  
                  &lt;/RelativeLayout&gt;
  
              &lt;/androidx.appcompat.widget.Toolbar&gt;
  
          &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:orientation=&quot;vertical&quot;
              android:layout_marginTop=&quot;10dp&quot;
              android:layout_below=&quot;@+id/app_bar_layout_post&quot;
              &gt;
              &lt;ImageView
                  android:id=&quot;@+id/PostImage&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;250dp&quot;
                  android:src=&quot;@drawable/add_image_icon&quot;
                  /&gt;
              &lt;EditText
                  android:id=&quot;@+id/PostInfo&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;5dp&quot;
                  android:hint=&quot;Describe your Giveaway...&quot;
                  /&gt;
  
  
          &lt;/LinearLayout&gt;
  
          &lt;Button
              android:id=&quot;@+id/publish&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginStart=&quot;249dp&quot;
              android:layout_marginTop=&quot;404dp&quot;
              android:layout_marginEnd=&quot;49dp&quot;
              android:layout_marginBottom=&quot;517dp&quot;
              android:text=&quot;publish&quot; /&gt;
  
          &lt;Button
              android:id=&quot;@+id/upload&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginStart=&quot;49dp&quot;
              android:layout_marginTop=&quot;404dp&quot;
              android:layout_marginEnd=&quot;249dp&quot;
              android:layout_marginBottom=&quot;517dp&quot;
              android:text=&quot;upload&quot; /&gt;
  
      &lt;/RelativeLayout&gt;
  &lt;/FrameLayout&gt;
  </code></pre>