Storage¶
We store mainly 3 things in the storage (images):
- Member photos
/avatars/{groupId}/{memberId}- max 512px and maintain aspect ratio
- JPG with compression 60%
- User photos
/profilePictures/{userId}- max 512px and maintain aspect ratio
- JPG with compression 60%
- Transaction receipts
/receipts/{groupId}/{expenseId}- max 2560px and maintain aspect ratio
- JPG with compression 85%
- These can also be PDFs
Photo can be added offline * First you add path of the local image to Firebase * Then you schedule a task for uploading (should be triggered only when device is online) * After the upload is complete, replace local path with remote path in Firebase
Storage Rules¶
Storage rules
rules_version = '2'
service firebase.storage {
match /b/{bucket}/o {
match /receipts/{groupId}/{expenseId} {
// If user knows groupId and it's signed in, allow read & write
allow read, write: if request.auth != null;
}
match /avatars/{groupId}/{memberId} {
// If user knows groupId and it's signed in, allow read & write
allow read, write: if request.auth != null;
}
match /archive/{groupId}/{filename} {
// If user knows groupId and it's signed in, allow read & write
allow read, write: if request.auth != null;
}
match /profilePictures/{userId} {
// Anyone signed in can read
allow read: if request.auth != null;
// Only user can edit own picture
allow write: if request.auth.uid == userId;
}
}
}