I'm looking to find a way to limit the amount of data a user can upload to their portion of my firebase database. I mentioned security rules as this would seem to be the easiest and safest way to implement but I'm open to any suggestions.
Lets say for example I have a firebase rtdb structured like the example below and I want to limit the overall amount of data in each 'User' branch. I'm not trying to limit how much they write on any given upload, just overall how much they have stored total. The app itself is a web app with html, js and css.
root-
- User1 //security rule to detect/set a max data limit for all User1 data
- Data: Some values
- Data2: Something else
//and so on
I looked for any similar questions but could not find anything relating to this particular need. If anyone has a link to documentation, article or solution I'm happy to do the reading!
Thanks in advance
CodePudding user response:
Firebase security rules cannot be used to limit size of a node. You can write data through a Cloud function that roughly calculates size of data being added (packages like object-sizeof
might be useful) and then stores the size somewhere in the database. You can then later check for the size before updating/adding data to that node.