TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Firebase Cloud Storage Setup and Configuration

Firebase Cloud Storage Setup and Configuration with What is Firebase, Features, Android Studio, Assistance, Adding Firebase to App, Installation, Data, Firebase Arrays, Event Types, Firebase Queries, Firebase Security etc.

<< Back to FIREBASE

Cloud Storage Setup and Configuration

In our previous section, we learned about Cloud Storage, its key capabilities, features, and how it works. Now, we will discuss how we set up and configure an Android application with Firebase to use Cloud Storage in our application. Just like Firebase Real-time Database and Firebase Firestore, Cloud Storage's starting steps are the same and will use Kotlin. So let's start with the starting steps and elaborate each step, which is performed to set up and configure the application to use Cloud Storage in Firebase.

Step 1:

In the first step, we will create a new Android Studio project with an empty activity and Kotlin language and give it name CloudStorageExample.

Cloud Storage Setup and Configuration

Step 2:

We will connect our Android Application with the Firebase either from Firebase Assistant or manually using console. After that, we will add all the required libraries and plugin to our app.gradle file. And we will also add mavenLocal() as our repository and all projects.

Cloud Storage Setup and Configuration
Cloud Storage Setup and Configuration
Cloud Storage Setup and Configuration

Step 3:

We will go to the Firebase console and look at the Firebase Cloud Storage in Developers-> Storage.

Cloud Storage Setup and Configuration

Step 4:

We will create a database by clicking on the Get started. After clicking on Get started, a popup box is open where we set storage with specific rules and click on Next.

Cloud Storage Setup and Configuration
Cloud Storage Setup and Configuration

After clicking on Next, a popup box will open. Here, we can select our Cloud Storage location depending on where we want to locate, and at last, click on Done.

Cloud Storage Setup and Configuration

Step 5:

After clicking on Done, a Cloud Storage will be created, which will look different from the real-time database and Cloud Firestore. Here, we have Files, Rules, and, Usage for file storing, security rules, and usage, respectively.

Cloud Storage Setup and Configuration
Cloud Storage Setup and Configuration

Step 6:

There is no need to change our security rules because, by default, an authenticated user can only read and write to the storage. These rules are defined as:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

If we want to make our Cloud Storage public, then the modification is done in the security rules are as followed:

//Everyone can read or write to the bucket, even non-user of our app.
//Because it is shared with Google App engine, this will also make files uploaded via the GAE public.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

If we want to use these rules for data validation that it can be possible. We can validate the file name and path. These rules are also used for validating metadata properties such as contentType and size.

service firebase.storage {
  match /b/{bucket}/o {
    match /images/{imageId} {// Upload onlt those image file that's less than 5MB
      allow write: if request.resource.size < 5 * 1024 * 1024
                   && request.resource.contentType.matches('image/.*');
    }
  }
}

Setup and configuration are completed here, and now we can implement our code to use this storage.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf