Skip to content

Firebase Storage Deep Dive — Secure File Uploads, Downloads, and Management

DodaTech Updated 2026-06-28 3 min read

In this tutorial, you will learn about Firebase Storage Deep Dive. We cover key concepts, practical examples, and best practices to help you master this topic.

Firebase Storage provides secure file uploads and downloads with Google Cloud Storage backend, supporting resumable uploads, download URLs, metadata, and integration with Firestore for file metadata management.

What You'll Learn

  • Uploading files with progress tracking
  • Generating download URLs and managing access
  • Organizing files and managing metadata

Why It Matters

File storage is essential for user-generated content. Firebase Storage handles scaling, security, and CDN delivery. DodaTech's antivirus quarantine files are stored in Firebase Storage with Firestore metadata linking.

Code Examples

// Upload file with progress
import { ref, uploadBytesResumable, getDownloadURL } from 'firebase/storage';
import { storage } from './firebase';

async function uploadFile(file, path) {
  const storageRef = ref(storage, `uploads/${path}/${file.name}`);
  const metadata = {
    contentType: file.type,
    customMetadata: {
      uploadedBy: auth.currentUser.uid,
      uploadedAt: new Date().toISOString()
    }
  };

  const uploadTask = uploadBytesResumable(storageRef, file, metadata);

  return new Promise((resolve, reject) => {
    uploadTask.on('state_changed',
      (snapshot) => {
        const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
        console.log(`Upload progress: ${progress}%`);
      },
      (error) => reject(error),
      async () => {
        const downloadUrl = await getDownloadURL(uploadTask.snapshot.ref);
        resolve({ url: downloadUrl, ref: storageRef });
      }
    );
  });
}
# Python Admin SDK: File operations
from google.cloud import storage

client = storage.Client()
bucket = client.get_bucket('project-id.appspot.com')

# Upload file
blob = bucket.blob('uploads/reports/report.pdf')
blob.upload_from_filename('report.pdf')

# Set metadata
blob.metadata = {
    'uploadedBy': 'admin',
    'department': 'security'
}
blob.patch()

# Generate download URL
url = blob.generate_signed_url(
    version='v4',
    expiration=3600,
    method='GET'
)
// File management and deletion
import { ref, deleteObject, listAll } from 'firebase/storage';

// Delete file
const fileRef = ref(storage, 'uploads/photos/photo.jpg');
await deleteObject(fileRef);

// List files in a directory
const listRef = ref(storage, 'uploads/photos');
const result = await listAll(listRef);
result.items.forEach(item => {
  console.log(item.fullPath);
});
result.prefixes.forEach(folder => {
  console.log('Folder:', folder.fullPath);
});

Common Mistakes

1. Storing Files Without Metadata in Firestore

Always store file metadata in Firestore for querying and management.

2. Using Public Download URLs for Private Files

Use signed URLs or security rules for access control.

3. Not Handling Upload Interruptions

Use resumable uploads for large files to resume on network interruption.

4. Forgetting to Delete Orphaned Files

When deleting Firestore documents, also delete associated storage files.

5. Uploading Files from Client Without Validation

Validate file types and sizes client-side and server-side.

Practice Questions

  1. How do you track upload progress?
  2. How do you generate a download URL?
  3. What is a signed URL?
  4. How do you organize files in Firebase Storage?
  5. How do you delete a file?

Answers:

  1. Use the state_changed Observer on uploadBytesResumable.
  2. Call getDownloadURL after the upload completes.
  3. A time-limited URL that provides temporary access to a private file.
  4. Use a folder-like path structure with forward slashes.
  5. Call deleteObject with the file reference.

Challenge: Build a file management system with upload, download, listing, deletion, and Firestore metadata. Implement folder organization, file type validation, size limits, and progress indicators.

FAQ

What is the maximum file size for Firebase Storage?

The maximum file size is 5 TB. However, files over 10 MB should use resumable uploads.

How does Firebase Storage pricing work?

You pay for storage (GB stored), downloads (GB transferred), and operations (upload, download, delete).

Can I use custom CDN domains with Firebase Storage?

Yes. Firebase Storage uses Google Cloud CDN. You can configure a custom domain in the Firebase Console.

How do I migrate existing files to Firebase Storage?

Use gsutil to copy files from existing storage to the Firebase Storage bucket.

Does Firebase Storage support multiple regions?

Yes. You can select a region when creating the Firebase project. Files are stored in Google Cloud Storage in that region.

Mini Project

Build a document management system with Firebase Storage. Implement file upload with type validation, folder organization, Firestore metadata linking, download URL generation with expiration, and integration with security rules for access control.

What's Next

Learn about Firebase Storage security rules for access control, then explore Cloud Functions for Serverless backend logic.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro