title: Firebase Storage Rules
body: <p>I'm very new to Firebase so hopefully this is a simple fix ...</p>
  
  <p>I have a couple basic storage rules setup just for testing, however it would seem that the rule for limiting the upload file size is not being honoured:</p>
  
  <p><strong>Storage Rules</strong></p>
  
  <pre><code>service firebase.storage {
    match /b/{bucket}/o {
      match /{allPaths=**} {
         allow read: if request.auth != null;
      }
      match /photos/{image} {
         allow write: if request.resource.size &lt; 3 * 1024 * 1024 &amp;&amp; request.auth != null;
      }
    }
  }
  </code></pre>
  
  <p>I have followed the rule code from here <a href="https://firebase.google.com/docs/storage/security/start" rel="nofollow noreferrer">https://firebase.google.com/docs/storage/security/start</a></p>
  
  <p>I have been able to upload a file over 5mb.  Firebase Storage reports file size of 5.33mb, more than the supposed 3mb limit.</p>
  
  <p>To check that the rule is recognised (that I have the correct path structure) I changed it to only allow a file its name was over 3 characters - I tried to upload a file with a longer name and it didn't permit this as expected.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Current app side code to upload to Storage (very basic 'messy' setup!). Basically I have a image file picker that returns to <code>onActivityResult</code>:</p>
  
  <pre><code>    private static final String PHOTO_URLS = "photo_links";
      private static final String PHOTOS_DATA = "photos";
  
      private FirebaseDatabase firebaseDatabase;
      private DatabaseReference photosDatabaseReference;
      private FirebaseStorage firebaseStorage;
      private StorageReference storageReference;
      private OnSuccessListener&lt;UploadTask.TaskSnapshot&gt; uploadSuccessListener;
      private OnFailureListener uploadFailureListener;
  
      @Override protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          firebaseDatabase = FirebaseDatabase.getInstance();
          photosDatabaseReference = firebaseDatabase.getReference().child(PHOTO_URLS);
          firebaseStorage = FirebaseStorage.getInstance();
          storageReference = firebaseStorage.getReference().child(PHOTOS_DATA);
          uploadSuccessListener = taskSnapshot -&gt; photosDatabaseReference.push().setValue(new PhotoEntry(taskSnapshot.getDownloadUrl().toString()));
          uploadFailureListener = Exception::printStackTrace;
      }
  
      @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if(resultCode == RESULT_OK){
              switch(requestCode){
                  case REQUEST_CODE_PHOTO:
                      uploadToFirebase(data.getData());
                      break;
                  case REQUEST_CODE_AUTH:
                      // stuff to handle Auth ...
                  default: break;
              }
          } else if (resultCode == RESULT_CANCELED) {
              makeText(this, "Operation cancelled", LENGTH_SHORT).show();
              if(requestCode == REQUEST_CODE_AUTH) finish();
          }
      }
  
      private void uploadToFirebase(Uri imageUri) {
          StorageReference reference = storageReference.child(imageUri.getLastPathSegment());
          reference.putFile(imageUri).addOnSuccessListener(uploadSuccessListener).addOnFailureListener(uploadFailureListener);
      }
  
      @Override protected void onDestroy() {
          super.onDestroy();
          uploadSuccessListener = null;
          uploadFailureListener = null;
      }
  </code></pre>
  
  <p>Where am I going wrong?</p>