Setup of Firebase Storage tutorial (step by step)
The Firebase environment needs a setup for each product, and in this article I’m setting up the Firebase Storage product. It is part 5 of an article series about the setup of the most used Firebase products. It is based on the first tutorial “Setup a Firebase project tutorial (step by step)” — please check that you are ready to add a product to a project. There is no code for an Android or Web app (see the links to my other articles for this topic). As most apps require a user authentication you should read the tutorial about the “Authentication” product as well.
What is Firebase ? Firebase is a set of backend cloud computing services and application development platforms provided by Google. It hosts databases, services, authentication, and integration for a variety of applications, including Android, iOS, JavaScript, Node.js, Java, Unity, PHP, and C++. (source: Wikipedia).
If you followed the article series you may wonder “after Firebase Realtime Database and Cloud Firestore Database, Firebase Storage is the third storage system ?”. The answer is yes and no because: yes, it a a third storage system but, no, not in the kind of the databases. They are designed to work with structured data or better datasets. This is an example of a dataset of an user: there are several data fields for one user (e.g. email address, user name, user image, last online timestamp). On the other hand the user may want to store images, audio and video files that need a place where to drop them. For that reason we do need a separate product that is called Firebase Storage.
Click on the button to proceed:
Click on “Get Started” to proceed:
The first step is about Security rules and I don’t really like the two possible options:
- start in start in production mode: means create an “unusable storage database” because no data can get appended, deleted or even read. Choose this option if you know what individual rules need to get setup in a following step.
- start in test mode: means the storage database will allow an unlimited read and write access without any limitations. As this setup is insecure the database has a time limit of 1 month. This option is good for testing purposes but there is a high risk that you forget about the time limit and
are surprised when your application stops to work properly.
Click on “Next” to proceed:
We need to choose at what server location the database should run — chose carefully as you cannot change this setting at a later time. As I’m located in Germany I have chosen “eur3 (Europe)”. Click on “Done”:
At this time the database is empty, but you should click on the “Rules” tab to edit the “production mode”. Change the existing (locking) rule to this values, meaning that only authenticated users are allowed to read and write to documents. This means on the other hand: every authenticated user can edit every document; a better solution could be that all user can read every document, but only the user who had created a document is allowed to edit the data. For more information about “rules” see https://firebase.google.com/docs/database/security. If you want to “play” with rules visit the “Rules Playground”.
rules_version = '2';
// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
After “Publishing” the rules our Storage is ready to store files.
Article series about Firebase:
- Setup of a Firebase project
- Setup of Firebase Authentication
- Setup of a Firebase Realtime Database
- Setup of a Cloud Firestore Database
- Setup of Firebase Storage (this article)
- Finish the setup of the Firebase project for an Android app tutorial (step by step)
- Finish the setup of the Firebase project for a Web app tutorial (step by step): will follow soon
- Firebase tutorial for an Android app (Java): will follow soon
- Firebase tutorial for a Web app (Javascript): will follow soon