kibudude
kibudude

Reputation: 79

Firebase storage rule resource variable returns null

I wrote a simple rule,

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /image/{fileName} {
      allow read: if resource != null;
      allow write: if false;
    }
  }
}

Then I added a file in /image folder in the default bucket. Using the Rules playground simulator tries a read request to the file and it failed. It is saying the resource is actually a null.

screen capture of Rules playground Any ideas why? From their documentation it seems like it should not do this or am I missing something? Any help will be highly appreciated.

(Update) Following was what I originally tried doing, checking for size

--- (Update in response to Franks post) Hi Frank, I tried exactly what you suggested, still no luck :(. Attaching the screenshot here.

screen shot 1

screen-shot 2

(Update) Frank's suggestion is correct, the file name mismatch was the issue as you originally suggested. The actual file name is scribble.jpg and I typed scibble.jpg in the simulator. After correcting, it was working as expected.

Upvotes: 1

Views: 518

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599946

While I thought I could reproduce the problem, after carefully copy/pasting the paths of some existing files, I can now no longer reproduce this in any project/test.

enter image description here

No idea what's going on for you, but I recommend copy/pasting the file names/paths as I did. Especially check for training spaces with in the file name, and in the Location value you enter in the playground, as they are incredibly easy to overlook and will cause the rules to fail.

Upvotes: 1

Related Questions