title: How to upload an image to Firebase storage?
body: <p>I'm trying to upload a simple byte array into Firebase storage, but my <code>onFailureListener</code> keeps getting called and logging back to me saying that the upload failed. I'm hoping you guys can tell me whats wrong with my code.</p>
  
  <p>At the top I got</p>
  
  <pre><code> //Firebase
      private Firebase mRef;
      private StorageReference storageRef;
  </code></pre>
  
  <p>Then in <code>onStart()</code></p>
  
  <pre><code>@Override
  protected void onStart() {
      super.onStart();
      googleApiClient.connect();
      //Firebase
      mRef = new Firebase("link to firebase account");
      FirebaseStorage storage = FirebaseStorage.getInstance();
      storageRef = storage.getReferenceFromUrl("link to storage");
  
  }
  </code></pre>
  
  <p>Then in my <code>onActivityResult()</code></p>
  
  <pre><code>      @Override
          protected void onActivityResult(int requestCode, int resultCode, Intent data) {
              addImageImageView.setVisibility(View.GONE);
              if (requestCode == Constants.REQUEST_CODE &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null) {
                  //First we gotta make sure to add the images to
                  ArrayList&lt;Image&gt; imagesFromGallery = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
                  for (int i = 0; i &lt; imagesFromGallery.size(); i++) 
                  {
                      try {
                          //try uploading it
                          InputStream stream = new FileInputStream(new File(imagesFromGallery.get(i).path));
                          StorageReference imageStorage = storageRef.child("cardImages/" + "testImages");
                          UploadTask uploadTask = imageStorage.putStream(stream);
                          uploadTask.addOnFailureListener(new OnFailureListener() {
                          @Override
                          public void onFailure(@NonNull Exception e) {
                              Log.d("myStorage","failure :(");
                          }
                      }).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
                          @Override
                          public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                              Log.d("myStorage","success!");
                          }
                      });
                      catch (UnsupportedEncodingException e) {
                      e.printStackTrace();
                      } catch (FileNotFoundException e) {
                       e.printStackTrace();
                  }
             }
        }
  </code></pre>
  
  <p>Here is my stack trace:</p>
  
  <pre><code>11-13 21:27:00.392 31388-996/com.daprlabs.aaron.swipedeck2 E/StorageException: StorageException has occurred.
     User does not have permission to access this object.
      Code: -13021 HttpResult: 403
  11-13 21:27:00.392 31388-996/com.daprlabs.aaron.swipedeck2 E/StorageException: The server has terminated the upload session
     java.io.IOException: The server has terminated the upload session
         at com.google.firebase.storage.UploadTask.az(Unknown Source)
         at com.google.firebase.storage.UploadTask.ay(Unknown Source)
         at com.google.firebase.storage.UploadTask.run(Unknown Source)
         at com.google.firebase.storage.StorageTask$5.run(Unknown Source)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
         at java.lang.Thread.run(Thread.java:818)
  11-13 21:27:00.406 31388-31388/com.daprlabs.aaron.swipedeck2 D/myStorage: failure :(
  </code></pre>