title: How to upload image to Firebase using kotlin
body: <p>This is what I have to far. I'm confused about getting instance and getting a reference for my picture in the URI format.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class MainActivity : AppCompatActivity(), View.OnClickListener {
  
      private val CAMERA_REQUEST_CODE = 12345
      private val REQUEST_GALLERY_CAMERA = 54654
      companion object {
          val TAG = "RegisterActivity"
      }
      val storage = FirebaseStorage.getInstance()
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          scnbtn.setOnClickListener(this)
      }
  
  
      override fun onClick(v: View?) {
          when (v) {
              scnbtn -&gt; {
                  if (Build.VERSION.SDK_INT &gt;= 23) {
                      if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                          ActivityCompat.requestPermissions(
                              this,
                              arrayOf(android.Manifest.permission.CAMERA, android.Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_GALLERY_CAMERA)
                      } else {
                          openCamera()
                      }
                  } else {
                      openCamera()
                  }
              }
          }
      }
  
      private fun openCamera() {
          val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
          if (intent.resolveActivity(packageManager) != null)
              startActivityForResult(intent, CAMERA_REQUEST_CODE)
      }
  
      override fun onRequestPermissionsResult(requestCode: Int, permissions: Array&lt;String&gt;, grantResults: IntArray) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults)
          if (requestCode == REQUEST_GALLERY_CAMERA) {
              if (grantResults[0] == PackageManager.PERMISSION_GRANTED &amp;&amp; grantResults[1] == PackageManager.PERMISSION_GRANTED) {
                  openCamera()
                  Log.d(TAG, "Button Pressed")
              } else {
                  Toast.makeText(this@MainActivity, "Fail", Toast.LENGTH_SHORT).show()
              }
          }
      }
  
      var selectedPhotoUri: Uri? = null
  
      override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          super.onActivityResult(requestCode, resultCode, data)
          if (resultCode == Activity.RESULT_OK) {
              when (requestCode) {
                  CAMERA_REQUEST_CODE -&gt; {
  
                      val extras = data?.getExtras()
                      val imageBitmap = extras?.get("data") as Bitmap
                      imagecap.setImageBitmap(imageBitmap)
                      val bytes = baos.toByteArray()
  
                      //FIREBASE
  
  
  
                      uploadImageToFirebaseStorage()
  
                      }
  
                  }
              }
          }
  
      private fun uploadImageToFirebaseStorage() {
  
          if (imagecap == null) return
  
          val filename = "images/" + UUID.randomUUID().toString()
          val ref = storage.getReference(filename)
  
          ref.putFile(imagecap!!)
              .addOnSuccessListener {
                  Log.d(TAG, "Successfully uploaded image: ${it.metadata?.path}")
  
                  ref.downloadUrl.addOnSuccessListener {
                      Log.d(TAG, "File Location: $it")
  
                  }
              }
              .addOnFailureListener {
                   Log.d(TAG, "Failed to upload image to storage: ${it.message}")
              }
      }
  
  }
  </code></pre>
  
  <p>Code works fine until it gets to firebase section. I cannot get the uploading to work. How does it know where the firebase storage is??</p>