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
-
Create a default Cloud Storage bucket in your Firebase Console
-
Deploy the default storage rules:
Terminal window firebase deploy --only storage -
The rules will be deployed from
storage.rules
:rules_version = '2';service firebase.storage {match /b/{bucket}/o {// User filesmatch /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 avatarfinal 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');}
// Get avatar URLfinal url = await storageService.instance .getUserAvatarUrl();
// Display in Image widgetImage.network(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.