title: How to reuse file value in Kotlin / Android app
body: <p><strong>Super</strong> new to Kotlin, literally day 1. I know python, c#, NodeJS, but no Java / Kotlin.</p>
  
  <p>I'm trying to build an example app that does 3 things:</p>
  
  <ul>
  <li><code>btn1</code> to select an image from the gallery (got that)</li>
  <li>show the image to the user (got that as well)</li>
  <li><code>btn2</code> to upload said image to an API (got this partially)</li>
  </ul>
  
  <p>I've got the scaffolding for step 3, however, I'm missing the reference to the image picked in step 1.
  <code>btn1</code> executes this:</p>
  
  <pre><code>private fun pickImageFromGallery() {
          //Intent to pick image
          val intent = Intent(Intent.ACTION_PICK)
          intent.type = "image/*"
          startActivityForResult(intent, IMAGE_PICK_CODE)
      }
  
  override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          if (resultCode == Activity.RESULT_OK &amp;&amp; requestCode == IMAGE_PICK_CODE){
              image_view.setImageURI(data?.data)
          }
      }
  </code></pre>
  
  <p>I now don't understand how I can use the reference to the image when the user clicks on <code>btn2</code>, seeing that the reference is passed to <code>onActivityResult</code> as the <code>data</code> object which seems to not be available to <code>btn2</code>.</p>
  
  <p>Most of this code is copy&amp;paste until it works, and the first two steps work well now.</p>
  
  <p>Any tips?</p>
  
  <p>Thanks!</p>