C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Cloud Storage Setup and ConfigurationIn 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. 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. Step 3: We will go to the Firebase console and look at the Firebase Cloud Storage in Developers-> Storage. 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. 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. 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. 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.
Next TopicCreating References in Cloud Storage
|