Add rule for maximum folder size limit for cloud storage in firebase

Viewed 1518

How can I add a rule to limit the maximum storage space size a user can consume? The current request.resource.size limits the size of a file a user can upload but not the folder/bucket size the user is uploading to. I wish to place a limit say 50 MB over all the content the user can upload.

Update:

To reframe the question, imagine the user has already uploaded 5 images of size 10MB each which makes it 50 MB altogether. Now I want to restrict the user from uploading any more files as the maximum bucket size (in my case: 50MB) is already reached. There could have been 2 files of 20 MB each and one of 10 MB, but the overall cap of 50 MB has to be respected. How do I add a rule for that?

Update 2:

Is it that in the current implementation, an authenticated user can keep on uploading an infinite amount of data say capped at 10 MB file size each at the expense of the user hosting the Firebase service (Assuming a pay as you go pricing model while hosting)?

2 Answers

The current design of Firebase does not allow creating rules to limit a bucket size.

A better implementation would be to track bucket size on your own server and also make all firebase uploads pass via your custom server. In essence, file gets uploaded to your server, passes bucket size check and then gets uploaded again to AWS S3 or Google Storage.

After this you can delete the upload from your server updating the metadata in your DB.

Related