Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 967
gonephishing Avatar asked Aug 08 '17 08:08

gonephishing


People also ask

How do I set Storage rules in Firebase?

To access your rules from the Firebase console, select your project, then in the left-hand navigation panel, click Storage. Click Rules once you're in the correct database or storage bucket. To access your rules from the Firebase CLI, go to the rules file noted in your firebase. json file.

What security rules are used for when accessing Cloud Storage through the Firebase console?

Firebase Security Rules for Cloud Storage integrates with Firebase Authentication to provide powerful user based authentication to Cloud Storage. This allows for granular access control based on claims of a Firebase Authentication token. When an authenticated user performs a request against Cloud Storage, the request.

Does Firebase Storage have CDN?

Firebase Hosting uses a powerful global CDN to make your site as fast as possible. Any requested static content is automatically cached on the CDN. If you redeploy your site's content, Firebase Hosting automatically clears all your cached static content across the CDN until the next request.


1 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.

like image 126
Code Create Avatar answered Oct 04 '22 04:10

Code Create