firebase-storage
Skill0 starsChanged 5 months agoMITView on GitHub
Configures and uses Cloud Storage for Firebase — provisioning buckets, writing security rules, uploading/downloading files from web and React Native, generating signed URLs from Cloud Functions, and integrating with Expo ImagePicker. Use whenever the user needs to store user-uploaded files, images, video, or any binary blob.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- evanca/flutter-ai-rulestheir own version, first seen Aug 24, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- evanca/flutter-ai-rules★ 669same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- firebase-ai-logicSkill
- firebase-analyticsSkill
- firebase-app-checkSkill
- firebase-architectureSkill
- firebase-authSkill
- firebase-cloud-functionsSkill
- firebase-cost-optimizationSkill
- firebase-crashlyticsSkill
- firebase-emulatorsSkill
- firebase-expoSkill
- firebase-firestoreSkill
- firebase-hostingSkill
- firebase-messagingSkill
- firebase-realtime-databaseSkill
- firebase-remote-configSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
If you need a secondary bucket (e.g.
- Distinctive: line 50
Default-deny, anchor to auth.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Cloud Storage for Firebase
Minimum viable example
import storage from "@react-native-firebase/storage";
const ref = storage().ref(`users/${uid}/avatar.jpg`);
await ref.putFile(localFileUri, { contentType: "image/jpeg" });
const url = await ref.getDownloadURL();Path scoped to the user (rules enforce ownership). putFile streams from disk so it works for large files without OOM.
1. Initialize storage
A default bucket is auto-created with each project. List existing buckets:
npx -y firebase-tools@latest storage:buckets:list 2>/dev/null || trueIf you need a secondary bucket (e.g. for public CDN content vs. user-private uploads):
gsutil mb -l <region> gs://<project-id>-publicInitialize Storage in your project root:
npx -y firebase-tools@latest init storageThis creates storage.rules.
2. Security rules
Default-deny, anchor to auth. Two common patterns:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
// User-private files
match /users/{userId}/{allPaths=**} {
allow read, write: if request.auth != null
&& request.auth.uid == userId
&& request.resource.size < 10 * 1024 * 1024 // 10 MiB
&& request.resource.contentType.matches('image/.*');
}
// Publicly readable, owner-writable
match /public/posts/{postId}/{file} {
allow read: if true;
allow write: if request.auth != null
&& firestore.get(/databases/(default)/documents/posts/$(postId)).data.authorId
== request.auth.uid;
}
}
}Deploy:
npx -y firebase-tools@latest deploy --only storageThe request.resource.size and contentType checks happen before the upload is admitted — they cap bandwidth and reject malicious uploads cheaply.
For cross-references with Firestore (firestore.get(...)), each call costs one Firestore read billed to your project.
3. Client SDK — Web
import { getStorage, ref, uploadBytes, getDownloadURL } from "firebase/storage";
const storage = getStorage();
const r = ref(storage, `users/${uid}/avatar.jpg`);
await uploadBytes(r, file, { contentType: "image/jpeg" });
const url = await getDownloadURL(r);For resumable uploads of large files:
import { uploadBytesResumable } from "firebase/storage";
const task = uploadBytesResumable(r, file);
task.on("state_changed",
(snap) => setProgress(snap.bytesTransferred / snap.totalBytes),
(err) => console.error(err),
async () => {
const url = await getDownloadURL(task.snapshot.ref);
},
);4. Client SDK — Expo / React Native
npx expo install @react-native-firebase/storageimport storage from "@react-native-firebase/storage";
// File URI from expo-image-picker, expo-document-picker, etc.
const ref = storage().ref(`users/${uid}/photo.jpg`);
await ref.putFile(localFileUri);
const url = await ref.getDownloadURL();putFile accepts a local file URI (no need to load the bytes into memory). For very large files this is dramatically more memory-efficient than the web SDK's uploadBytes.
For Expo ImagePicker integration see references/expo-image-picker.md.
5. Signed URLs from Cloud Functions
Download URLs from the client SDK are tied to a token that lives in the file's metadata. To revoke access, you have to rotate the token (delete + reupload, or call updateMetadata with firebaseStorageDownloadTokens deleted). For controlled access, generate signed URLs from a Cloud Function instead:
import { getStorage } from "firebase-admin/storage";
import { onCall, HttpsError } from "firebase-functions/v2/https";
export const getSignedUrl = onCall(async (request) => {
if (!request.auth) throw new HttpsError("unauthenticated", "");
const path = request.data.path as string;
// Authorize: does this user own this path?
if (!path.startsWith(`users/${request.auth.uid}/`)) {
throw new HttpsError("permission-denied", "");
}
const [url] = await getStorage().bucket().file(path).getSignedUrl({
action: "read",
expires: Date.now() + 15 * 60 * 1000, // 15 minutes
});
return { url };
});Signed URLs work without the Firebase SDK and expire on a deadline you choose.
6. Cost & performance
- Caching: set
Cache-Control: public, max-age=31536000in metadata for immutable assets (hashed filenames). Reduces egress bills significantly. - Resize on the fly: install the official Resize Images extension (
npx -y firebase-tools@latest ext:install firebase/storage-resize-images) to auto-generate thumbnails. - Delete on user deletion: hook
beforeUserDeleted(seefirebase-cloud-functionstriggers) and bulk-delete the user's prefix, otherwise files orphan forever and keep billing. - Don't list large prefixes from the client.
listAll()returns up to 1000 entries per page and is slow + expensive at scale. Maintain a Firestore index of file paths instead.
7. Common mistakes
- Storing download URLs in Firestore long-term. They include a token that may rotate or be revoked. Store the path and call
getDownloadURL(ref(storage, path))at read time, or use signed URLs. - Not setting
contentTypeon upload. Browsers refuse to display files served with the wrong MIME. The web SDK infers from theFileobject; manual uploads must set it explicitly. - Skipping size checks in rules. Without
request.resource.size < N, a single attacker can upload terabytes and bill you. - Mixing
gs://URIs and HTTPS URLs. The SDK accepts both viaref()but third-party tools (CDNs,<img src>) need the HTTPS download URL.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

