Firebase Tutorial
- Home
- Introduction
- Project Setup
- Authentication (Email/Pass)
- Social Authentication
- Cloud Firestore (Basics)
- Firestore Queries
- Real-time Updates
- Firestore Security Rules
- Cloud Storage
- Storage Security Rules
- Cloud Functions (Intro)
- Triggering Functions
- Firebase Hosting
- Firebase Analytics
- Crashlytics & Performance
- Remote Config
- App Check
- Offline Persistence
- Firebase with Next.js
- Best Practices
Cloud Storage
Cloud Storage for Firebase is built for app developers who need to store and serve user-generated content, such as photos or videos.
1. Initialize Storage
import { getStorage } from "firebase/storage";
const storage = getStorage(app);2. Upload a File
First, create a Reference to the path where you want the file to live.
import { ref, uploadBytes } from "firebase/storage";
const storageRef = ref(storage, 'images/profile.jpg');
// 'file' comes from an <input type="file">
uploadBytes(storageRef, file).then((snapshot) => {
console.log('Uploaded a blob or file!');
});3. Get Download URL
After uploading, you usually need a URL to display the image in your app.
import { getDownloadURL } from "firebase/storage";
getDownloadURL(storageRef)
.then((url) => {
// You can use this URL as src for an <img> tag
console.log("Download URL:", url);
});4. Delete a File
import { deleteObject } from "firebase/storage";
deleteObject(storageRef).then(() => {
console.log("File deleted successfully");
});Pro Tip: Cloud Storage scales automatically to petabytes of data, so you don't have to worry about server disk space!