38

I am new to firebase storage. Can anyone tell me how to make the storage files public for reading and writing?. The default code provided by firebase is given below. What changes should I make ?

service firebase.storage {
  match /b/image-view-b1cf5.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
ashay
  • 1,115
  • 2
  • 9
  • 11

6 Answers6

81

FYI: if you want public read only.

service firebase.storage {
  match /b/image-view-b1cf5.appspot.com/o {
    match /{allPaths=**} {
        allow read;
        allow write: if request.auth != null;
    }
  }
} 
Ego Slayer
  • 1,987
  • 2
  • 22
  • 17
54

The documentation explains that if no rule expression is provided, the rule evaluates to true:

service firebase.storage {
  match /b/image-view-b1cf5.appspot.com/o {
    match /{allPaths=**} {
      // Allow access by all users
      allow read, write;
    }
  }
}
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
  • That doesn't remind us that our storage is public, as it does in firebase database. Are you sure this is the only way of making it public? – ashay Jul 29 '16 at 15:23
  • @ashay: If you need a reminder, add a comment to the rule. – Bob Snyder Jul 29 '16 at 15:26
3

Just Removing

if request.auth != null;

service firebase.storage {
  match /b/image-view-b1cf5.appspot.com/o {
    match /{allPaths=**} {
      // Allow access by all users
      allow read, write;
    }
  }
}

Happy Coding

Kalpesh A. Nikam
  • 324
  • 3
  • 10
3
// Anyone can read or write to the bucket, even non-users of your app.
// Because it is shared with Google App Engine, this will also make
// files uploaded via GAE public.
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}
Kishan Solanki
  • 13,761
  • 4
  • 85
  • 82
0
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
} 
Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
saigopi.me
  • 14,011
  • 2
  • 83
  • 54
0

Removing the authentication condition should work.

Saikat halder
  • 548
  • 4
  • 11
  • This is not true. – Taslim Oseni Jan 17 '19 at 18:29
  • If you don't change auto generated code, it is public, and can be accessed by the link it provides. – Saikat halder Jan 18 '19 at 19:07
  • This is not true. It is protected by default (only authenticated users). Check the docs out: https://firebase.google.com/docs/storage/security/ – Taslim Oseni Jan 19 '19 at 07:51
  • Here's the excerpt from the docs I posted above: **For example, the default Storage Security Rules require Firebase Authentication in order to perform any read or write operations on all files.** – Taslim Oseni Jan 19 '19 at 07:52
  • I made a cross platform data transfer from a set of android devices to a windows pc. For android devices, authentication was used but for pc version, no authentication was used by me and it works smoothly. – Saikat halder Jan 19 '19 at 08:09
  • I think you should delete this answer now since it's misleading. – Taslim Oseni Jan 19 '19 at 11:07