Skip to content

Cloud Storage

ShipFlutter uses Firebase Cloud Storage to store and serve user files. The storage module provides a simple interface for common operations like uploading user avatars.

Setup

  1. Create a default Cloud Storage bucket in your Firebase Console

  2. Deploy the default storage rules:

    Terminal window
    firebase deploy --only storage
  3. The rules will be deployed from storage.rules:

    rules_version = '2';
    service firebase.storage {
    match /b/{bucket}/o {
    // User files
    match /users/{userId}/{allPaths=**} {
    allow read: if request.auth != null;
    allow write: if request.auth.uid == userId;
    }
    }
    }

Storage Service

The StorageService class provides a type-safe way to interact with Cloud Storage:

// Upload user avatar
final file = await imagePicker.pickImage(
source: ImageSource.gallery,
);
if (file != null) {
final url = await storageService.instance
.uploadUserAvatar(file);
// Use the download URL
print('Avatar URL: $url');
}

File Organization

ShipFlutter follows this storage structure:

  • Directoryusers/
    • Directory$userId/
      • avatar // User profile picture
      • Directoryfiles/ // User uploaded files

Each user gets their own storage space under their user ID, ensuring proper isolation and security.