# Firebase Storage

> Use when setting up Storage, uploading/downloading files, managing metadata, handling errors, or applying security rules.

- **Type:** Skill
- **Install:** `agentstack add skill-evanca-flutter-ai-rules-firebase-storage`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [evanca](https://agentstack.voostack.com/s/evanca)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [evanca](https://github.com/evanca)
- **Source:** https://github.com/evanca/flutter-ai-rules/tree/main/skills/firebase-storage

## Install

```sh
agentstack add skill-evanca-flutter-ai-rules-firebase-storage
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Firebase Cloud Storage Skill

This skill defines how to correctly use Firebase Cloud Storage in Flutter applications.

## When to Use

Use this skill when:

* Setting up Cloud Storage in a Flutter project.
* Uploading or downloading files.
* Managing file metadata.
* Handling Storage errors and monitoring upload progress.

---

## 1. Setup and Configuration

```
flutter pub add firebase_storage
```

```dart
import 'package:firebase_storage/firebase_storage.dart';

final storage = FirebaseStorage.instance;
// Or specify a bucket explicitly:
// final storage = FirebaseStorage.instanceFor(bucket: "gs://BUCKET_NAME");
```

- Firebase Storage requires the **Blaze (pay-as-you-go) plan**.
- Run `flutterfire configure` to update your Firebase config with the default Storage bucket name.

> **Security note:** By default, a Cloud Storage bucket requires Firebase Authentication for any action. Configuring public access may also make App Engine files publicly accessible — restrict access again when you set up Authentication.

---

## 2. File Operations

**Create a reference:**

```dart
final storageRef = FirebaseStorage.instance.ref();
final fileRef = storageRef.child("uploads/file.jpg");
```

**Upload:**

```dart
final uploadTask = fileRef.putFile(file);
final snapshot = await uploadTask;
final downloadUrl = await snapshot.ref.getDownloadURL();
```

**Download (in-memory):**

```dart
final data = await fileRef.getData();
```

**Download URL:**

```dart
final downloadUrl = await fileRef.getDownloadURL();
```

**Delete:**

```dart
await fileRef.delete();
```

---

## 3. Metadata Management

**Get metadata:**

```dart
final metadata = await fileRef.getMetadata();
print('Content type: ${metadata.contentType}');
print('Size: ${metadata.size}');
```

**Update metadata:**

```dart
final newMetadata = SettableMetadata(
  contentType: "image/jpeg",
  customMetadata: {'uploaded_by': 'user123'},
);
await fileRef.updateMetadata(newMetadata);
```

Use **custom metadata** to store additional key/value pairs with your files.

---

## 4. Error Handling

Use `try-catch` with `FirebaseException`. Key error codes:

| Code | Meaning |
|---|---|
| `storage/object-not-found` | File doesn't exist at the reference |
| `storage/bucket-not-found` | No bucket configured for Cloud Storage |
| `storage/project-not-found` | No project configured for Cloud Storage |
| `storage/quota-exceeded` | Storage quota exceeded |
| `storage/unauthenticated` | User needs to authenticate |
| `storage/unauthorized` | User lacks permission |
| `storage/retry-limit-exceeded` | Operation timeout exceeded |

- For `quota-exceeded` on the Spark plan, upgrade to Blaze.
- Implement retry logic for network-related errors and timeouts.

---

## 5. Performance and Best Practices

**Monitor upload progress:**

```dart
final uploadTask = fileRef.putFile(file);
uploadTask.snapshotEvents.listen((TaskSnapshot snapshot) {
  print('Progress: ${(snapshot.bytesTransferred / snapshot.totalBytes) * 100}%');
});
```

- **Cancel** uploads with `uploadTask.cancel()`.
- **Pause / resume** with `uploadTask.pause()` and `uploadTask.resume()`.
- Optimize file sizes before upload to reduce costs and improve performance.
- Use Cloud Storage with Firestore for comprehensive data management.
- Use the **Firebase Local Emulator Suite** for local development and testing.

---

## 6. Security

- Use **Firebase Security Rules** to control access to files.
- Combine Storage rules with **Firebase Authentication** for user-based access control.
- Test security rules thoroughly before deploying to production.

---

## References

- [Firebase Cloud Storage Flutter documentation](https://firebase.google.com/docs/storage/flutter/start)
- [Upload files](https://firebase.google.com/docs/storage/flutter/upload-files)
- [Download files](https://firebase.google.com/docs/storage/flutter/download-files)
- [Handle errors](https://firebase.google.com/docs/storage/flutter/handle-errors)

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [evanca](https://github.com/evanca)
- **Source:** [evanca/flutter-ai-rules](https://github.com/evanca/flutter-ai-rules)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-evanca-flutter-ai-rules-firebase-storage
- Seller: https://agentstack.voostack.com/s/evanca
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
