Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A Quiz
🔍 Overview
Firebase isn’t just about authentication and databases—it
also includes powerful tools for file storage, web hosting, and push
notifications. These services help developers build scalable, media-rich,
and real-time communication-enabled applications with ease.
This chapter dives into:
📁 Part 1: Firebase Cloud
Storage
🔹 What Is Firebase
Storage?
Firebase Storage is built on Google Cloud Storage
and provides a robust, secure, and scalable way to store and serve
user-generated content such as images, audio, and video.
🔹 Key Features:
🔧 Setup Firebase Storage
Step 1: Enable Storage in Firebase Console
Step 2: Add Firebase SDK
groovy
// Android build.gradle dependencies
implementation 'com.google.firebase:firebase-storage:20.3.0'
🧪 Upload a File (Android
Example)
java
FirebaseStorage
storage = FirebaseStorage.getInstance();
StorageReference
storageRef = storage.getReference();
Uri
file = Uri.fromFile(new File("path/to/image.jpg"));
StorageReference
imagesRef = storageRef.child("images/image.jpg");
imagesRef.putFile(file)
.addOnSuccessListener(taskSnapshot -> {
Log.d("Upload", "Upload
successful!");
})
.addOnFailureListener(e -> {
Log.e("Upload", "Upload
failed", e);
});
📥 Download a File
java
imagesRef.getDownloadUrl()
.addOnSuccessListener(uri -> {
Log.d("Download URL",
uri.toString());
});
🔐 Secure Your Files with
Rules
js
rules_version
= '2';
service
firebase.storage {
match /b/{bucket}/o {
match /images/{imageId} {
allow read, write: if request.auth !=
null;
}
}
}
📊 Firebase Storage Use
Cases
Use Case |
Description |
Profile picture
uploads |
Allow users to upload
avatars |
Audio/video hosting |
Store media
for streaming apps |
PDF/Docs handling |
Serve eBooks or
reports |
E-commerce image storage |
Product
images and banners |
🌐 Part 2: Firebase
Hosting
🔹 What is Firebase
Hosting?
Firebase Hosting provides fast, secure, and reliable
hosting for static and dynamic web content (HTML, CSS, JS, media files, and
APIs). It’s backed by a global CDN and supports custom domains
and SSL certificates.
🔹 Features:
🔧 Setup Firebase Hosting
Step 1: Initialize Firebase Project
bash
firebase
init hosting
Step 2: Deploy
bash
firebase
deploy --only hosting
🧪 Hosting Example: Static
Site
Place your HTML files in a public/ folder:
pgsql
public/
├── index.html
├── style.css
└── script.js
Firebase automatically deploys the entire folder to a secure
URL like:
https://your-project-id.web.app
🌐 Add a Custom Domain
📊 Hosting Use Cases
Type |
Examples |
Single-page apps
(SPA) |
React, Angular, Vue
apps |
Portfolios & landing pages |
Personal
websites, resumes |
Admin dashboards |
Internal tools hosted
securely |
Hybrid apps |
Combine
Hosting + Cloud Functions API |
📲 Part 3: Firebase Cloud
Messaging (FCM)
🔹 What is Firebase Cloud
Messaging?
Firebase Cloud Messaging (FCM) enables you to send push
notifications and in-app messages across Android, iOS, and web
platforms. It’s ideal for user engagement, alerts, promotions, and
transactional messages.
🔹 Core Benefits:
🔧 Set Up FCM in Android
Step 1: Add Dependencies
groovy
implementation
'com.google.firebase:firebase-messaging:23.2.1'
Step 2: Setup Firebase Messaging Service
java
public
class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage
remoteMessage) {
Log.d("FCM", "Message:
" + remoteMessage.getNotification().getBody());
}
}
Step 3: Handle Token Refresh
java
@Override
public
void onNewToken(String token) {
Log.d("FCM", "New token:
" + token);
// Send token to your server if needed
}
🧪 Sending Notification
from Firebase Console
✅ Sending via API (Node.js)
js
const
admin = require("firebase-admin");
const
message = {
notification: {
title: "Sale Alert!",
body: "50% off only today!",
},
token: userDeviceToken,
};
admin.messaging().send(message)
.then(response => {
console.log("Notification sent:",
response);
})
.catch(error => {
console.error("Error:", error);
});
🎯 Advanced FCM Features
Feature |
Description |
Topic Messaging |
Subscribe users to
groups (e.g., news) |
Device Groups |
Send to
multiple devices of one user |
Condition Targeting |
topicA &&
!topicB logic support |
Analytics |
Track opens,
CTR, delivery failures |
🧠 Best Practices
🧩 Comparison Table
Feature |
Firebase Storage |
Firebase Hosting |
Firebase Cloud
Messaging |
Stores |
Media files |
HTML/CSS/JS + APIs |
Notification payloads |
Integration |
Android, iOS,
Web |
Static/dynamic
content |
Android, iOS,
Web |
Security |
Auth + Rules |
SSL + Public rules |
Token-based access |
Scalable |
Yes |
Yes |
Yes |
Pricing |
Storage-based |
Bandwidth-based |
Free (limits on high
volume) |
Offline support |
Yes
(on-device cache) |
No |
No (except queued
messages) |
📌 Conclusion
Firebase Storage, Hosting, and Cloud Messaging together
empower developers to build complete apps—from storing user files, hosting
dashboards, to engaging users with push alerts. These services work
hand-in-hand with Firebase Auth, Firestore, and Cloud Functions to provide a
seamless full-stack experience.
In the next chapter, we’ll explore Bonus Tools & Tips
to improve productivity and optimize performance in Firebase-powered apps.
Firebase is a Backend-as-a-Service (BaaS) platform by Google that offers a suite of tools like real-time databases, authentication, cloud storage, hosting, and analytics—enabling developers to build fully functional mobile apps without managing servers.
Yes, Firebase supports Android, iOS, and even cross-platform frameworks like Flutter and React Native, offering SDKs and libraries that make integration smooth across platforms.
Realtime Database is a low-latency JSON-based database ideal for syncing data in real-time. Firestore, on the other hand, is more scalable, supports structured collections/documents, and offers more advanced querying and offline support.
Absolutely. Firebase Authentication supports email/password, phone number, and social logins with built-in security, encrypted data transmission, and session management.
Yes, through Firebase Cloud Functions, you can write server-side logic (like sending notifications, validating data, or processing payments) that runs in response to events—all without managing physical servers.
Firebase offers a free-tier plan (Spark Plan) which includes many core features. As your usage grows, you can switch to the Blaze Plan (pay-as-you-go), which scales with your app's needs.
Firebase is built on Google Cloud infrastructure, making it highly scalable. Cloud Firestore and Cloud Functions scale automatically based on usage, ideal for apps with growing user bases.
Yes, Firebase is modular. You can use only the features you need—like Authentication or Cloud Messaging—without being forced to use the whole stack.
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Comments(0)